proctk Posted April 22, 2006 Share Posted April 22, 2006 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.phpthank 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] Quote Link to comment https://forums.phpfreaks.com/topic/8101-up-date-user-information/ Share on other sites More sharing options...
s2day Posted April 22, 2006 Share Posted April 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8101-up-date-user-information/#findComment-29570 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.