likeaaron Posted March 4, 2009 Share Posted March 4, 2009 Hi all I'm having a bit of trouble with this script. I should be able to read the contents of the table - display it - and then update the table when I submit the changes. At the moment it can read and display the table data but it wont make any changes. Here is a live preview http://rsl.likeaaron.com/admin/edit.php heres the code <? //connect to mysql include("_db_conn.php"); //If cmd has not been initialized if(!isset($cmd)) { $result = mysql_query("select * from heading order by id"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the news $head=$r["head"];//take out the title $id=$r["id"];//take out the id //make the title a link echo "<a href='edit.php?cmd=edit&id=$id'>$head - Edit</a>"; echo "<br>"; } } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM heading WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> heading:<INPUT TYPE="TEXT" NAME="head" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> body:<TEXTAREA NAME="body" ROWS=10 COLS=30><? echo $myrow["body"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $head = $_POST["head"]; $body = $_POST["body"]; $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id"; $result = mysql_query($sql) or die (mysql_error()); echo "Ok"; } } ?> Thankyou in advance. Please Help Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/ Share on other sites More sharing options...
sasa Posted March 4, 2009 Share Posted March 4, 2009 change <? if ($_POST["$submit"]) { $head = $_POST["head"]; $body = $_POST["body"]; $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id"; $result = mysql_query($sql) or die (mysql_error()); echo "Ok"; } } ?> to <?php if ($_POST["$submit"]) { $ip = $POST['id']; $head = $_POST["head"]; $body = $_POST["body"]; $sql = "UPDATE heading SET head='$head',body='$body' WHERE id=$id"; $result = mysql_query($sql) or die (mysql_error()); echo "Ok"; } } ?> Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776087 Share on other sites More sharing options...
likeaaron Posted March 4, 2009 Author Share Posted March 4, 2009 that didn't work Any other ideas? Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776092 Share on other sites More sharing options...
T-Bird Posted March 4, 2009 Share Posted March 4, 2009 $ip = $POST['id']; I think you mean $id=$_POST['id]. Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776097 Share on other sites More sharing options...
likeaaron Posted March 4, 2009 Author Share Posted March 4, 2009 $ip = $POST['id']; I think you mean $id=$_POST['id]. already spotted that and didnt change the outcome do you think that it has something to do with the form action? Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776099 Share on other sites More sharing options...
likeaaron Posted March 4, 2009 Author Share Posted March 4, 2009 any1? Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776287 Share on other sites More sharing options...
likeaaron Posted March 4, 2009 Author Share Posted March 4, 2009 fixed changed if ($_POST["[b]$submit[/b]"]) to if ($_POST["[b]submit[/b]"]) Link to comment https://forums.phpfreaks.com/topic/147866-solved-cannot-update-mysql-field-pulling-my-hair-out/#findComment-776323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.