bickyz Posted February 23, 2010 Share Posted February 23, 2010 hi this is my code, and it doesnt updates after clickin on submit button. Without errors it goes back to the page with the link. <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("mydb"); //If cmd has not been initialized if(!isset($cmd)) { //display all the news $result = mysql_query("select * from news 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 $title=$r["title"];//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'>$title - Edit</a>"; echo "<br>"; } } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM news 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"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br> Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br> Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $title = $_POST["title"]; $message = $_POST["message"]; $who = $_POST["who"]; $sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> Quote Link to comment Share on other sites More sharing options...
alpine Posted February 23, 2010 Share Posted February 23, 2010 if ($_POST["$submit"]) if ($_POST["submit"]) Quote Link to comment Share on other sites More sharing options...
bickyz Posted February 23, 2010 Author Share Posted February 23, 2010 if ($_POST["$submit"]) if ($_POST["submit"]) i changed that but still not updating. I turned error reporting on and it says "Notice: Undefined index: cmd in /home/centos/public_html/spoono/edit.php on line 33" and line 33 is this code: if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") Quote Link to comment Share on other sites More sharing options...
alpine Posted February 23, 2010 Share Posted February 23, 2010 add this on top of your script to debug whats posted and whats not, replace with $_GET to debug get variables echo "<pre>"; print_r($_POST); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
bickyz Posted February 23, 2010 Author Share Posted February 23, 2010 add this on top of your script to debug whats posted and whats not, replace with $_GET to debug get variables echo "<pre>"; print_r($_POST); echo "</pre>"; it displays like this with both $_POST & $_GET Array ( ) record1-edit record2-edit record3-edit record4-edit Quote Link to comment Share on other sites More sharing options...
alpine Posted February 23, 2010 Share Posted February 23, 2010 Then you have no post data from your form - for some reason Quote Link to comment 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.