Fearpig Posted August 11, 2006 Share Posted August 11, 2006 Hi Guys,Can anyone help me? I've been struggling through various tutorials and I'm stuck on editing MySQL data with PHP.Can someone take a looka t the code below and suggest where I'm going wrong? :)<? //connect to mysql//change user and password to your mySQL name and passwordmysql_connect("localhost","root","password"); mysql_select_db("Telephonelist"); //If cmd has not been initializedif(!isset($cmd)) { //display all the people $result = mysql_query("SELECT * FROM tbl_telephonenumbers 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 $First=$r["First_Name"];//take out the title $Last=$r["Last_Name"];//take out the title $ID=$r["ID"];//take out the id //make the title a link echo "<a href='Edit_SpecificPerson.php?cmd=edit&ID=$ID'>$First $Last</a>"; echo "<br>"; }}//If cmd has been initializedif(isset($cmd)) { if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["ID"]; $sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$ID"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="Edit_SpecificPerson.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["ID"] ?>"> First Name:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br> Last Name:<INPUT TYPE="TEXT" NAME="message" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br> Role:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? }} if(isset($submit)) { if ($_POST["$submit"]) { $First = $_POST["First_Name"]; $Last = $_POST["Last_Name"]; $Role = $_POST["Role"]; $sql = "UPDATE tbl_telephonenumbers SET First_Name='$First',Last_Name='$Last',Role='$Role' WHERE ID=$ID"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}}?>The first two pass throughs it works OK. - On the first pass it list all the names as a link. - On the second pass it populate text boxes with the details you selected (by which name you clicked on)- On the third pass it fails. This is when you click submit and the database should be updated with any changes made into the text boxes.This is the error page that comes up:Notice: Undefined index: cmd in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 31Notice: Undefined index: First_Name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 61Notice: Undefined index: Last_Name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 62Notice: Undefined index: Role in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 63Notice: Undefined variable: ID in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 65Thank you! Information updated. - the information is not updated and any help will be REALLY appreciated as I've been hacking at this for days now and it all seems a bit of a blur!Cheers Tom Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 11, 2006 Share Posted August 11, 2006 get rid on theseif(isset($submit)) {add to post like thisif(isset($_POST['submit'])){} Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 Hi Redarrow,Do you mean change just the end section to:if(isset($_POST['submit']){ $First = $_POST["First_Name"]; $Last = $_POST["Last_Name"]; $Role = $_POST["Role"]; $sql = "UPDATE tbl_telephonenumbers SET First_Name='$First',Last_Name='$Last',Role='$Role' WHERE ID=$ID"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}If so it now won't run up at all and has the error:Parse error: parse error, unexpected T_VARIABLE in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 59 Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 11, 2006 Share Posted August 11, 2006 sorry dont change nothink 1 min reading code Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 11, 2006 Share Posted August 11, 2006 if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")to if($_GET["cmd"]=="edit" && $_POST["cmd"]=="edit") Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 11, 2006 Share Posted August 11, 2006 //If cmd has been initializedif(isset($cmd)) { if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"]))<<<<<< ! that be there ? { $id = $_GET["ID"]; $sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$ID"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 11, 2006 Share Posted August 11, 2006 you set $id=$_GET['ID']; $sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$ID";to $sql = "SELECT * FROM tbl_telephonenumbers WHERE id=$id";get me you made the letters id small haha Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 Hi Redarrow,So which of those changes do I use.... could you post a complete script? Thanks for all your help.Tom 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.