Sydcomebak Posted July 25, 2008 Share Posted July 25, 2008 I know I need to do something in the <form> tag, but I don't know how to make the reset & update buttons to function once I've edited the textboxes. $resident is a rowID passed from the previous page. TIA. <?php $dbcnx = @mysql_connect("__.__.__.__", "_user_", "_pw_"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } if (! @mysql_select_db("_db_") ) { echo( "<P>Unable to locate the " . "database at this time.</P>" ); exit();} ?> <html> <form> <?php $result = mysql_query("SELECT * FROM ResidentTbl INNER JOIN PeopleTbl ON ( PeopleTbl.NameID = ResidentTbl.Name_ID ) WHERE ResidentID = '$resident' ") OR die(mysql_error()); WHILE ($row = mysql_fetch_array($result) ) { echo "<img src=\"viewpic.php?file={$resident}\">"; echo "<table border=1>"; echo "<tr><td align=right><b>Prefix:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_prefix". '"'. "value=". $row[NamePrefix]. "></td></tr>"; echo "<tr><td align=right><b>First Name:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_first". '"'. "value=". $row[NameFirst]. "></td></tr>"; echo "<tr><td align=right><b>Middle:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_middle". '"'. "value=". $row[NameMiddle]. "></td></tr>"; echo "<tr><td align=right><b>Last Name:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_last". '"'. "value=". $row[NameLast]. "></td></tr>"; echo "<tr><td align=right><b>Suffix:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_suffix". '"'. "value=". $row[NameSuffix]. "></td></tr>"; echo "</table>"; echo "<hr>"; echo "<table border=1>"; echo "<tr><td><input type=". '"'. "text". '"'. "name=". '"'. "phone_cell". '"'. "value=". $row[PhoneCell]. "></td><td align=left><b>Cell:</b></td></tr>"; echo "<tr><td><input type=". '"'. "text". '"'. "name=". '"'. "phone_work". '"'. "value=". $row[PhoneWork]. "></td><td align=left><b>Work:</b></td></tr>"; echo "</table>"; echo "<table border=1><tr>"; echo "<td><input id=". '"'. "submit". '"'. " name=". '"'. "submit". '"'. " type=". '"'. "submit". '"'. " value=". '"'. "Update & Close". '"'. "></td>"; echo "<td><input id=". '"'. "reset". '"'. " name=". '"'. "reset". '"'. " type=". '"'. "reset". '"'. " value=". '"'. "Reset". '"'. "></td>"; echo "</tr></table>"; } ?> </form> </html> Link to comment https://forums.phpfreaks.com/topic/116622-editing-info-updating-the-db/ Share on other sites More sharing options...
s0c0 Posted July 25, 2008 Share Posted July 25, 2008 Yeah fix your form: <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> They way you are doing this will make it difficult. What you will need to do for the text fields name is name it something like phone-36 where 36 is the primary key of that particular row in the database. Now once the data has been posted explode on the hyphen and update the phone field with what ever $_POST['phone-36'] is equal to where the user equals 36. Does that make sense? Link to comment https://forums.phpfreaks.com/topic/116622-editing-info-updating-the-db/#findComment-599651 Share on other sites More sharing options...
Sydcomebak Posted July 25, 2008 Author Share Posted July 25, 2008 Like this? -Dave <?php $dbcnx = @mysql_connect("__.__.__.__", "_user_", "_pw_"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } if (! @mysql_select_db("_db_") ) { echo( "<P>Unable to locate the " . "database at this time.</P>" ); exit();} ?> <html> <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <?php $result = mysql_query("SELECT * FROM ResidentTbl INNER JOIN PeopleTbl ON ( PeopleTbl.NameID = ResidentTbl.Name_ID ) WHERE ResidentID = '$resident' ") OR die(mysql_error()); WHILE ($row = mysql_fetch_array($result) ) { echo "<img src=\"viewpic.php?file={$resident}\">"; echo "<table border=1>"; echo "<tr><td align=right><b>Prefix:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_prefix-". $resident. '"'. "value=". $row[NamePrefix]. "></td></tr>"; echo "<tr><td align=right><b>First Name:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_first-". $resident. '"'. "value=". $row[NameFirst]. "></td></tr>"; echo "<tr><td align=right><b>Middle:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_middle-". $resident. '"'. "value=". $row[NameMiddle]. "></td></tr>"; echo "<tr><td align=right><b>Last Name:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_last-". $resident. '"'. "value=". $row[NameLast]. "></td></tr>"; echo "<tr><td align=right><b>Suffix:</b></td><td><input type=". '"'. "text". '"'. "name=". '"'. "name_suffix-". $resident. '"'. "value=". $row[NameSuffix]. "></td></tr>"; echo "</table>"; echo "<hr>"; echo "<table border=1>"; echo "<tr><td><input type=". '"'. "text". '"'. "name=". '"'. "phone_cell-". $resident. '"'. "value=". $row[PhoneCell]. "></td><td align=left><b>Cell:</b></td></tr>"; echo "<tr><td><input type=". '"'. "text". '"'. "name=". '"'. "phone_work-". $resident. '"'. "value=". $row[PhoneWork]. "></td><td align=left><b>Work:</b></td></tr>"; echo "</table>"; echo "<table border=1><tr>"; echo "<td><input id=". '"'. "submit". '"'. " name=". '"'. "submit". '"'. " type=". '"'. "submit". '"'. " value=". '"'. "Update & Close". '"'. "></td>"; echo "<td><input id=". '"'. "reset". '"'. " name=". '"'. "reset". '"'. " type=". '"'. "reset". '"'. " value=". '"'. "Reset". '"'. "></td>"; echo "</tr></table>"; } ?> </form> </html> Link to comment https://forums.phpfreaks.com/topic/116622-editing-info-updating-the-db/#findComment-599658 Share on other sites More sharing options...
Sydcomebak Posted July 25, 2008 Author Share Posted July 25, 2008 No idea though how to "explode" on the hyphen to submit the data. Link to comment https://forums.phpfreaks.com/topic/116622-editing-info-updating-the-db/#findComment-599671 Share on other sites More sharing options...
Sydcomebak Posted July 26, 2008 Author Share Posted July 26, 2008 I think it merits mentioning that I'm referencing 1 resident at a time, and their unique row ID is $resident which was already passed from the previous page. I need to clean this up a bit, I think. I'm selecting * from PeopleTbl and ResidentTbl. That will be a lot of values to update and in the right order, right? Or is it as simple as saying: PeopleTbl.NameFirst=this.form.FirstName? Link to comment https://forums.phpfreaks.com/topic/116622-editing-info-updating-the-db/#findComment-600134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.