fl00d
08-01-2007, 06:13 AM
Hi,
I'm having trouble getting the fopen & fwrite functions to work. I've included them in an admin panel script to make for easy, online editing. For some reason, the info isn't getting passed, and I don't know why. I think it may have to do with $_GET & $_POST conflicting with each other.
What happens is I click the link for the page I want to edit, it shows the form and I click the 'Update' button and the page returns blank. It doesn't even echo that it failed.
Anyone have an idea? I don't :confused:
<?php
session_start();
if(@$_SESSION['admin'] != "yes"){
echo "You are not admin.";
}else{
include("/home/flawclan/public_html/config.php");
$connect = mysql_connect("$host","$user","$passwd");
mysql_select_db("$dbname",$connect);
$table_name = "cms"; //table
//navbar query
$page = $_GET['page'];
$sql = "SELECT * FROM $table_name";
$query = mysql_query($sql,$connect);
while($row = @mysql_fetch_array($query)){
$id = $row['content_id'];
$title = $row['page_title'];
echo "<a href=\"admincp.php?page=".$id."\">Edit $title page</a><br />";
}
if($page == "1"){
$pagename = "main.php";
}
if($page == "2"){
$pagename = "news.php";
}
if($page == "3"){
$pagename = "roster.php";
}
if($page == "4"){
$pagename = "downloads.php";
}
if($page == "5"){
$pagename = "server.php";
}
if($page == "6"){
$pagename = "about.php";
}
//content page query
$sql = "SELECT content_id FROM $table_name WHERE content_id='$page'";
$query = mysql_query($sql,$connect);
while($row = @mysql_fetch_array($query)){
switch($_POST['button']){
case "Update":
$file = fopen("/home/flawclan/public_html/pages/".$pagename."", "w");
$content = $_POST['content'];
$write = fwrite($file,$content);
if($write){
echo "Updated sucessfully";
}else{
echo "Darn it... something went wrong";
}
fclose($file);
break;
default:
echo "<center><p>Editing $pagename";
echo "<form action=";
echo "admincp.php";
echo " method=\"post\">
<textarea name=\"content\"></textarea><br />
<input type=\"submit\" value=\"Update\" name=\"button\"></form>";
}
}
}
?>
Thanks for any possible help!
I'm having trouble getting the fopen & fwrite functions to work. I've included them in an admin panel script to make for easy, online editing. For some reason, the info isn't getting passed, and I don't know why. I think it may have to do with $_GET & $_POST conflicting with each other.
What happens is I click the link for the page I want to edit, it shows the form and I click the 'Update' button and the page returns blank. It doesn't even echo that it failed.
Anyone have an idea? I don't :confused:
<?php
session_start();
if(@$_SESSION['admin'] != "yes"){
echo "You are not admin.";
}else{
include("/home/flawclan/public_html/config.php");
$connect = mysql_connect("$host","$user","$passwd");
mysql_select_db("$dbname",$connect);
$table_name = "cms"; //table
//navbar query
$page = $_GET['page'];
$sql = "SELECT * FROM $table_name";
$query = mysql_query($sql,$connect);
while($row = @mysql_fetch_array($query)){
$id = $row['content_id'];
$title = $row['page_title'];
echo "<a href=\"admincp.php?page=".$id."\">Edit $title page</a><br />";
}
if($page == "1"){
$pagename = "main.php";
}
if($page == "2"){
$pagename = "news.php";
}
if($page == "3"){
$pagename = "roster.php";
}
if($page == "4"){
$pagename = "downloads.php";
}
if($page == "5"){
$pagename = "server.php";
}
if($page == "6"){
$pagename = "about.php";
}
//content page query
$sql = "SELECT content_id FROM $table_name WHERE content_id='$page'";
$query = mysql_query($sql,$connect);
while($row = @mysql_fetch_array($query)){
switch($_POST['button']){
case "Update":
$file = fopen("/home/flawclan/public_html/pages/".$pagename."", "w");
$content = $_POST['content'];
$write = fwrite($file,$content);
if($write){
echo "Updated sucessfully";
}else{
echo "Darn it... something went wrong";
}
fclose($file);
break;
default:
echo "<center><p>Editing $pagename";
echo "<form action=";
echo "admincp.php";
echo " method=\"post\">
<textarea name=\"content\"></textarea><br />
<input type=\"submit\" value=\"Update\" name=\"button\"></form>";
}
}
}
?>
Thanks for any possible help!