simcoweb Posted October 31, 2006 Share Posted October 31, 2006 I have member profiles that I would like them to be able to update from a member control panel link that uses their memberid to summon their data into a prepopulated form. I'm using this method to populate the form fields with their current data. Not sure if this is the right way to do it but it's the way I have working now:MySQL:[quote]$sql = "SELECT * FROM plateau_pros WHERE memberid='$memberid'";$result = mysql_query($sql, $conn) or die(mysql_error());[/quote]page and form displayed as:[code]<?phpwhile ($a_row = mysql_fetch_array($result)) { echo " <form action='updatemember.php' method='POST'> <table width='95%' border='0' align='center'> <tr> <td><font class='bodytext'>First name: </td><td><input type='text' size='30' value='" . $a_row['firstname'] . "'></td> </tr> <tr> <td><font class='bodytext'>Last name: </td><td><input type='text' size='30' value='" . $a_row['lastname'] . "'></td> </tr> <tr> <td><font class='bodytext'>Business name: </td><td><input type='text' size='30' value='" . $a_row['business'] . "'></td> </tr> <tr> <td><font class='bodytext'>Your title: </td><td><input type='text' size='30' value='" . $a_row['title'] . "'></td> </tr> <tr> <td><font class='bodytext'>Address: </td><td><input type='text' size='30' value='" . $a_row['address'] . "'></td> </tr> <tr> <td><font class='bodytext'>City: </td><td><input type='text' size='30' value='" . $a_row['city'] . "'></td> </tr> <tr> <td><font class='bodytext'>Zip code: </td><td><input type='text' size='30' value='" . $a_row['zip'] . "'></td> </tr> <tr> <td><font class='bodytext'>Phone: </td><td><input type='text' size='30' value='" . $a_row['phone'] . "'></td> </tr> <tr> <td><font class='bodytext'>Fax: </td><td><input type='text' size='30' value='" . $a_row['fax'] . "'></td> </tr> <tr> <td><font class='bodytext'>Email: </td><td><input type='text' size='30' value='" . $a_row['email'] . "'></td> </tr> <tr> <td><font class='bodytext'>Details: </td><td><textarea cols='30' rows='5' value=''>" . $a_row['comments'] . "</textarea></td> </tr> <tr> <td><font class='bodytext'>Specialties: </td><td><textarea cols='30' rows='5' value=''>" . $a_row['specialties'] . "</textarea></td> </tr> <tr> <td><input type='submit' value='Update' name='update'></td> </tr> </table> </form> <p>\n";?>[/code]The form gets populated with the current data. They can edit their changes then hit 'Update' button which would then write this query:[code]<?php$sql = "UPDATE plateau_pros SET firstname='$firstname', lastname='$lastname', business='$business', title='$title', address='$address', city='$city', zip='$zip', phone='$phone', fax='$fax', mobile='$mobile', email='$email', comments='$comments', specialties='$specialties' WHERE memberid='$memberid'";$result = mysql_query($sql, $conn) or die(mysql_error());?>[/code]Which, when I [code]<?php echo $result ?>[/code] I get the number '1' which indicates one row has been updated. However, when I check the fields in the MySQL database nothing has been changed or added. Quote Link to comment Share on other sites More sharing options...
sinisake Posted October 31, 2006 Share Posted October 31, 2006 :)One small thing is missing-'name' attrribut for textfields:First name: <td><input type='text' size='30' value='" . $a_row['firstname'] . "'></td>should be:<td><input type='text' [color=blue][font=Verdana]name='firstname' [/font][/color]size='30' value='" . $a_row['firstname'] . "'></td>Also, pay attention to retrieve $_POST($vars) properly. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted October 31, 2006 Author Share Posted October 31, 2006 DOHHHHHHHHh! Ok, overlooked that in my haste. That's why it's always good to have another set of eyes looking at this stuff. Sometimes the obvious becomes the oblivious.I'll insert the name tags.For this:[quote]Also, pay attention to retrieve $_POST($vars) properly.[/quote]Can you elaboarate on what you mean by that? Thanks for the post! Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 31, 2006 Share Posted October 31, 2006 also, usually if you're just making a script with SQL that executes a query, and you're not retrieving data, you don't put the query into a variable, you just execute it. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted October 31, 2006 Author Share Posted October 31, 2006 Ok, cool. That's good to know. Learn a little bit every day :) 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.