cadac Posted October 28, 2011 Share Posted October 28, 2011 I have managed to create an update script that allows a user to submit changes to their details but I need help to finish of the code. I'm using sessions to login in members, here is my update.php code. After while($member = mysql_fetch_array($result)) { I would like to retrieve the new values entered by them to be displayed back to the previous form which uses $_SESSION to hold their information when they previously login. Any suggestions or ideas, as I think it's to do with clearing the session but unfamiliar on how to proceed. <?php include("config.php"); mysql_connect("$dbhost","$dbuser","$dbpass") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error()); $id= mysql_real_escape_string($_POST['member_id']); $fname= mysql_real_escape_string($_POST['firstname']); $lname= mysql_real_escape_string($_POST['lastname']); $address= mysql_real_escape_string($_POST['address']); $town= mysql_real_escape_string($_POST['address2']); $county= mysql_real_escape_string($_POST['county']); $postcode= mysql_real_escape_string($_POST['postcode']); $telephone= mysql_real_escape_string($_POST['telephone']); $mobile= mysql_real_escape_string($_POST['mobile']); $username= mysql_real_escape_string($_POST['login']); $email=mysql_real_escape_string($_POST['email']); $id= $_POST['member_id']; $sql="UPDATE members SET firstname='$fname', lastname='$lname', address='$address', address2='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', login='$username', email='$email' WHERE member_id='$id' LIMIT 1"; $result=mysql_query($sql) or die ("Error: ". mysql_error(). " with query ". $sql); $query = "SELECT * FROM members WHERE member_id = '$id'"; $result = mysql_query($query) or die(mysql_error()); while($member = mysql_fetch_array($result)) { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249969-passing-new-mysql-values-to-form/ Share on other sites More sharing options...
Nodral Posted October 28, 2011 Share Posted October 28, 2011 Use something like if(strlen($_POST['variablename'])>1{ echo $_POST['variablename']; } else { echo "result from DB"; } This way if they have entered something on the form, it will POST it back to the form when they reload the page, if nothing has been POSTed, then it will put the data from the DB in there. Quote Link to comment https://forums.phpfreaks.com/topic/249969-passing-new-mysql-values-to-form/#findComment-1283065 Share on other sites More sharing options...
cadac Posted October 28, 2011 Author Share Posted October 28, 2011 I thanks for replying, tried that and the displayed when echoed but trying to post back to the form, no luck Quote Link to comment https://forums.phpfreaks.com/topic/249969-passing-new-mysql-values-to-form/#findComment-1283087 Share on other sites More sharing options...
sabinmash Posted November 28, 2011 Share Posted November 28, 2011 Great scott! I checked it before and completely overlooked the missing variable. I turned it into username rather than user_id, because it's more readily available and both are unique. the function now looks like this: function get_survey_query1($gender,$birth_range,$degree_year,$username) { $survey1_query = "UPDATE `alumni_survey`.`user` SET `gender` = '".$gender."', `birth_range` = '".$birth_range."', `degree_year` = '".$degree_year."' WHERE `user`.`username` = '".$username."'"; return $survey1_query; } Thank you again. Quote Link to comment https://forums.phpfreaks.com/topic/249969-passing-new-mysql-values-to-form/#findComment-1291897 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.