Jump to content

Passing new mysql values to form


cadac

Recommended Posts

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)) {	


}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.