DeanWhitehouse Posted May 10, 2008 Share Posted May 10, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/ Share on other sites More sharing options...
peranha Posted May 10, 2008 Share Posted May 10, 2008 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/#findComment-537282 Share on other sites More sharing options...
DeanWhitehouse Posted May 10, 2008 Author Share Posted May 10, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/#findComment-537285 Share on other sites More sharing options...
AndyB Posted May 10, 2008 Share Posted May 10, 2008 Would you mind editing that so that your conditional loops are indented ... otherwise it's almost impossible to follow what's meant to be your logic flow. Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/#findComment-537286 Share on other sites More sharing options...
DeanWhitehouse Posted May 10, 2008 Author Share Posted May 10, 2008 edited for easier reading, but still have a problem. is it my update statement? "UPDATE hayleyedit SET content = '{$update}' WHERE page_id = '{$page_id}'"; Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/#findComment-537289 Share on other sites More sharing options...
DeanWhitehouse Posted May 10, 2008 Author Share Posted May 10, 2008 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/104961-solved-sql-update-not-working-with-textarea/#findComment-537299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.