jomcfall97 Posted April 30, 2009 Share Posted April 30, 2009 hi im having trouble with making a page to update a set of records held in a mysql table here is the html file that im using to allow a user to search for a customer by name i was hoping to use this to then open a page with the users details displayed but in an editable form <html> <head> <title>Search for User to edit</title> </head> <center><h1><font face="Bookman Old Style">Search for User to edit</font></h1></center> <br> <ul class="navbar"> <br> <br> <br> <br> <br> <br> <li><a href="home.html">Main Page</a></li> <li><a href="staffarea.html">Back</a></li> </ul> <br> <br> <center><FORM ACTION="../cgi-bin/edit.php" METHOD="POST"> <strong> Search for a user name to edit: <input text type="text" name="name" size=20> </strong> <br> <br> <INPUT TYPE=SUBMIT VALUE="Submit"> <INPUT TYPE=RESET VALUE="Reset"> </FORM></center> </body> </html> here is the php code ive got that displays the users details but i dont know how to make it editable #!c:/php/php.exe <html> <head> <title>Edit User</title> </head> <center><h1><font face="Bookman Old Style">Edit User</font></h1></center> <br> <ul class="navbar"> <br> <br> <br> <br> <br> <br> <li><a href="../home.html">Main Page</a></li> <li><a href="../staffarea.html">Back</a></li> </ul> <br> <br> <br> <br> <?php $server="localhost"; $username ="student1"; $password="student1pw"; $database="localdatabase"; $name = $_REQUEST['name']; $connect = mysql_connect($server,$username,$password); //$connect = mysql_connect("localhost","root",""); if (!$connect){ die ("Cannot connect to $server using $user"); }else{ print ("Connect to server successfully!<br>"); mysql_select_db("localdatabase", $connect ) or die("database error!") ; print ("Open database sucessfully! <br />"); $result = mysql_query( "SELECT * FROM survey WHERE name = \"$name\" ") or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=100 border=1>\n"; print "<th>Name</th><th>Address</th><th>Postcode</th><th>Telephone Number</th><th>Email</th><th>Question 1</th><th>Question 2</th><th>Question 3</th><th>Question 4</th><th>Question 5</th><th>Question 6</th><th>Question 7</th><th>Question 8</th><th>Question 9</th>"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=5/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; mysql_close($connect); print ("database closed!"); } ?> </body> </html> any help appreciated thanks Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/ Share on other sites More sharing options...
jomcfall97 Posted April 30, 2009 Author Share Posted April 30, 2009 any suggestions even where to start? please :-\ Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/#findComment-823105 Share on other sites More sharing options...
mikesta707 Posted April 30, 2009 Share Posted April 30, 2009 I'm assuming you know how to send those values to an edit page. Just populate a form with those values, and people can edit the forms as they see. once they submit the form you can go to a page the updates the table with the new information. Obviously you will have to pass an Id or some other variable that is unique for every row to figure out which row you need to update. Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/#findComment-823117 Share on other sites More sharing options...
jomcfall97 Posted April 30, 2009 Author Share Posted April 30, 2009 sorry could you give me an example - i dont know what an edit page is or how to send the data to it Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/#findComment-823119 Share on other sites More sharing options...
jomcfall97 Posted May 1, 2009 Author Share Posted May 1, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/#findComment-823181 Share on other sites More sharing options...
mikesta707 Posted May 1, 2009 Share Posted May 1, 2009 alright well on the page that displays the user's information, and instead of just echoing the information, make aform, and set the values of the forms as the information from the table. FOr example, to make the password changeable, do something like echo "<input type=\"password\" value=\"$password\" /> that would make a password input field with the value of the users password. when they submit that form, it would go to a page that updates their specific entry for the user Quote Link to comment https://forums.phpfreaks.com/topic/156323-update-a-mysql-table/#findComment-823187 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.