Jump to content


Photo

Up Date User Information


  • Please log in to reply
1 reply to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 22 April 2006 - 01:57 AM

Below is code that I'm using to display a users information . I'm trying to figure out how I can change this so that it can be used to update a users information via a form call UpdateMyInformation.php

thank you for any help



<?php session_start(); ?>

<html>
<head>
<title>Get My Info</title>
</head>

<body>
<?

include 'db.php';

$username = $_SESSION['username']; 
echo($username);

// note, if userid is not a numeric type column, then $userid must be quoted
$query = "SELECT * FROM users WHERE username = '$username'";
$result = @mysql_query($query);

if(!$result)
{
  trigger_error("<p>SQL ERROR:<br>".mysql_error()."<br>Query: $query</p>",
                E_USER_WARNING);
}
elseif(mysql_numrows($result) != 1)
{
  trigger_error("<p>DB ERROR: There were multiple matches on this User ID</p>",
                E_USER_WARNING);
}
else  // we got exactly one match on the User ID
{
   echo "<b><center>Database Output</center></b><br><br>";
   
   // only 1 match, so we don't need a loop
   $row = mysql_fetch_assoc($result);
   extract($row, EXTR_PREFIX_ALL, "user");
   mysql_close();
   
   echo <<<END
   
<b>$user_first_name $user_last_name</b><br>
Date of Birth: $user_DOB<br>
<b>Address</b><br>
Street Address: $user_Street_address<br>
Other Mailing Information: $user_post_office_box<br>
City: $user_city <br>
Province: $user_province<br>
Postal Code: $user_postal<br>
Home Phone Number: $user_home_phone<br>
Email Address: $user_email_address<br>

<hr><br>
END;
}

?>
</body> 


#2 s2day

s2day
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 April 2006 - 12:50 PM

updateinfo.php can be something like this:

<? //mysql query calling for the data you want to be updated to fill in the values in the form below ?>
<form name="update" action="process.php" method="post">
Field Name : <input type="text" name="field_name" value="<? echo $row->field_value;?>">
Field Name1 : <input type="text" name="field_name1" value="<? echo $row->field_value1;?>">
Field Name2 : <input type="text" name="field_name2" value="<? echo $row->field_value2;?>">
</form>
on the process.php page, something like this:

<? if ($_POST['field_name']){
mysql_query("UPDATE `tablename` SET `field_name`='$_POST[field_name]', `field_name1`='$_POST[field_name]1', `field_name2`='$_POST[field_name2]'") or die (mysql_error());
echo "fields updated!";
?>

again, this is very basic..it bypasses other common and useful things you may want to use like check for blank/invalid entries, strip any tags someone may enter into a form field, check for duplicates (like duplicate username or email if that is what's updated), etc etc.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users