Jump to content

Up Date User Information


proctk

Recommended Posts

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



[code]
<?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>
[/code]
Link to comment
Share on other sites

updateinfo.php can be something like this:

[code]
<? //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>
[/code]
on the process.php page, something like this:

[code]
<? 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!";
?>
[/code]

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.

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.