Jump to content

[SOLVED] sql update not working with textarea


DeanWhitehouse

Recommended Posts

this is my code

<?php
if ($_SESSION['logged_in'] == true)
{
if (isset($_GET['editpageid'])) {
if ((int) $_GET['editpageid'] > 0) {

$page_id = $_GET['editpageid'];
$sql = "SELECT * FROM hayleyedit WHERE page_id ='{$page_id}' LIMIT 0,1;";
$result = mysql_query($sql) or die("Error:" . mysql_error());
$row = mysql_fetch_assoc($result);
$welcome = $row['content'];
$name = $row['page_name'];
?>
<p>Editing <?php echo "$name"; ?></p>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"><textarea name="content" cols="60" rows="20" title="Edit Site Content"><?php echo "$welcome"; ?></textarea><br /><input type="submit"  value="Change" title="Save Changes" name="save"/></form>
<?php

if (mysql_num_rows($result) < 1) {
     echo 'This ID does not exist in the database<br>';
 echo "<a href=\"live_edit.php\">Return to Page List</a>";
 exit();
}
exit();
}
else {
echo "Unknown Page ID! <br />";
echo "<a href=\"live_edit.php\">Return to Page List</a>";
exit();
}
}
//No ID passed to page, display user list:
$query = "SELECT page_name, content, page_id FROM hayleyedit ORDER BY page_id";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
echo "Page List:<br />";
while ($row = mysql_fetch_assoc($result)) {
  echo '<table border="1"><tr><td><a href="?editpageid=' . $row['page_id'] . '">' . $row['page_name'] . '</a></td></tr></table>';
}
}
}
else
{
header("Location:http://".$_SERVER[HTTP_HOST]);
}

if(isset($_POST['save']))
{
$update =mysql_real_escape_string($_POST['content']);
$query_update = "UPDATE hayleyedit SET content = '{$update}' WHERE page_id = '{$page_id}'";
mysql_query ($query_update) or die("Error:" . mysql_error());
}

mysql_close();
?>

 

there are no errors , it reloads the page after i submit it and my changes aren't made, and they are not changed in th DB either. anyone help?

Where are you connecting to the database?

 

Also, this should be at the beginning of the file.

 

if(isset($_POST['save']))

{

$update =mysql_real_escape_string($_POST['content']);

$query_update = "UPDATE hayleyedit SET content = '{$update}' WHERE page_id = '{$page_id}'";

mysql_query ($query_update) or die("Error:" . mysql_error());

}

 

i am connecting to the database before the code you can see,

 

this is my whole code (without connection details)

<?php
if(isset($_POST['save']))
{
$update =mysql_real_escape_string($_POST['content']);
$query_update = "UPDATE hayleyedit SET content = '{$update}' WHERE page_id = '{$page_id}'";
mysql_query ($query_update) or die("Error:" . mysql_error());
}

if ($_SESSION['logged_in'] == true)
{
if (isset($_GET['editpageid'])) {
	if ((int) $_GET['editpageid'] > 0) {

	$page_id = $_GET['editpageid'];
	$sql = "SELECT * FROM hayleyedit WHERE page_id ='{$page_id}' LIMIT 0,1;";
	$result = mysql_query($sql) or die("Error:" . mysql_error());
	$row = mysql_fetch_assoc($result);
	$welcome = $row['content'];
	$name = $row['page_name'];
	?>
	<p>Editing <?php echo "$name"; ?></p>
	<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"><textarea name="content" cols="60" rows="20" title="Edit Site Content"><?php echo "$welcome"; ?></textarea><br /><input type="submit"  value="Change" title="Save Changes" name="save"/></form>
	<?php

		if (mysql_num_rows($result) < 1) {
			 echo 'This ID does not exist in the database<br>';
			 echo "<a href=\"live_edit.php\">Return to Page List</a>";
			 exit();
		}
	exit();
	}


	else {
	 echo "Unknown Page ID! <br />";
	 echo "<a href=\"live_edit.php\">Return to Page List</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT page_name, content, page_id FROM hayleyedit ORDER BY page_id";
$result = mysql_query($query) or die("Error:" . mysql_error());

	if (mysql_num_rows($result) > 0) {
	echo "Page List:<br />";
	while ($row = mysql_fetch_assoc($result)) {
	  echo '<table border="1"><tr><td><a href="?editpageid=' . $row['page_id'] . '">' . $row['page_name'] . '</a></td></tr></table>';
	}
	}
}
else
{
header("Location:http://".$_SERVER[HTTP_HOST]);
}

mysql_close();
?>
</div>
</div>

 

I need the update to update the content with the page ID it has, that is in the URL as

?editpageid=(whatever id)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.