Fearpig Posted August 11, 2006 Share Posted August 11, 2006 Hello,Can anyone recomend a tutorial on editing MySQL data with PHP forms. I've tried a hundred ways and I just get stuck. :'(Cheers Tom Quote Link to comment Share on other sites More sharing options...
brown2005 Posted August 11, 2006 Share Posted August 11, 2006 wat do you want to do, retrieve the data from a table in a form for editing.... is it one record at a time or multiple Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 Hi,Basically its a telephone book. I want to list all names as links. When you click on the link it takes you to a form where you can edit the details for that person (first_name, last_name, role, number, department... etc.) . It seems simple enough and I can get most of it working but the last few steps seem to outwit everybody so I was going back to basics. Quote Link to comment Share on other sites More sharing options...
brown2005 Posted August 11, 2006 Share Posted August 11, 2006 email me the link to rberbe2002@msn.com so i can have a look mate Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 Sorry... its on an IntrAnet server with no public access! The webserver doesn't have PHP / MySQL. Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 Can anyone recommend a tutorial or lesson I can download...? ??? Quote Link to comment Share on other sites More sharing options...
Fearpig Posted August 11, 2006 Author Share Posted August 11, 2006 ;DWent back to basics and did it already..... just incase anyone else was having the same issue.... or thinking about it can anyone spot a problem with doing it this way?I did this in three pages:1. list of clickable names that link to a form - Edit_ListPeople.php2. A form to fill out and post results - Edit_Person.php3. A page to process the form contents - Edit_ProcessForm.phpEdit_ListPeople.php[code]<html><head></head><body><?php$db = mysql_connect("localhost", "root", "password");mysql_select_db("Telephonelist",$db);$result = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);echo "<table border=1>\n";echo "<tr><td><b>Name</b></td><td><b>Position</b></tr>\n";//colum nameswhile ($myrow = mysql_fetch_array($result)) { printf("<tr><td><a href=\"%s?id=%s\">%s %s</a></td><td>%s</td></tr>\n", //lay out results 2 in the first column and 1 in the second "Edit_Person.php", $myrow["ID"], $myrow["First_Name"], $myrow["Last_Name"], $myrow["Role"]);}echo "</table>\n";?></body></html>[/code]Edit_Person.php[code]<html><head></head><body><?php$db = mysql_connect("localhost", "root", "password");mysql_select_db("Telephonelist",$db);$id = $_GET["id"];$sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$id";$result = mysql_query($sql); $myrow = mysql_fetch_array($result);?> <form action="Edit_ProcessForm.php" method="post"> <input type=hidden name="Frm_ID" value="<?php echo $myrow["ID"] ?>"> First Name:<INPUT TYPE="TEXT" NAME="Frm_First" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br> Last Name:<INPUT TYPE="TEXT" NAME="Frm_Last" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br> Role:<INPUT TYPE="TEXT" NAME="Frm_Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form></body></html>[/code]Edit_ProcessForm.php[code]<html><head></head><body><?php$db = mysql_connect("localhost", "root", "password");mysql_select_db("Telephonelist",$db);$id = $_POST["Frm_ID"];$First = $_POST["Frm_First"];$Last = $_POST["Frm_Last"];$Role = $_POST["Frm_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.";echo "<br>";echo "<a href='index.htm'>Click here to return to the phone index</a>";?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 11, 2006 Share Posted August 11, 2006 It looks that should work fine for you.However, be sure to validate user input before updating the database.Head to the link below for more information:http://www.phpfreaks.com/phpmanual/page/security.database.sql-injection.html 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.