Okay I have this user update form working and it does update as long as information is placed in all fields of the form. For the areas that have nothing added it replaces what was in the table with a blank entry which I do not want. All that needs to change is the input they have changed. How would I go about fixing this so it only updates what the member has changed?
// Set the page title and include the HTML header.
$page_title = 'Member Profile Update';
include_once ('incl/header.html');
session_start(); // Start a session.
// If no first_name variable exists, redirect the user.
if (!isset($_SESSION['user_id'])) {
header ("Location: [url]http://[/url]" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean();
exit();
} else {
if (isset($_POST['submit'])) { // Handle the form.
require_once ('../mysql_connect.php'); // Connect to the database.
$sql="SELECT * FROM user WHERE user_id={$_SESSION['user_id']}";
$query = "UPDATE user SET location='$location' , email='$email',homepage='$homepage', biography='$biography', interests='$interests', occupation='$occupation'
WHERE user_id={$_SESSION['user_id']}";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
} else { // If it did not run OK.
// Send a message to the error log, if desired.
$message = '<p>Your information could not be changed due to a system error.</p>';
}
mysql_close(); // Close the database connection.
}
} // End of the main Submit conditional.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align=center width=100% border="1" bordercolor="#8080C0">
<tr><td colspan=2 background="img/nav_bg.jpg" align=center valign=middle>
<?php
if (isset($SESSION['user_id'])) {
echo "Update {$SESSION['username']} Profile";
} else {
echo '';
}
?>
</td></tr>
<tr>
<td>Location:</td>
<td><input type="text" name="location" size="25" maxlength="50" value="<?php if (isset($POST['location'])) echo $POST['location']; ?>" /></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($POST['email'])) echo $POST['email']; ?>" /></td>
</tr>
<tr>
<td height="47">Homepage:</td>
<td><input type="text" name="homepage" size="50" maxlength="50" value="<?php if (isset($POST['homepage'])) echo $POST['homepage']; ?>" /></td>
</tr>
<tr>
<td> Biography:</td>
<td><textarea name="biography" cols="50" rows="15" value="<?php if (isset($POST['biography'])) echo $POST['biography']; ?>" /></textarea>
</td>
</tr>
<tr>
<td> Interests:</td>
<td><textarea name="interests" cols="50" rows="5" value="<?php if (isset($POST['interests'])) echo $POST['interests']; ?>" /></textarea>
</td>
</tr>
<tr>
<td height="47">Occupation:</td>
<td><input type="text" name="occupation" size="50" maxlength="50" value="<?php if (isset($POST['occupation'])) echo $POST['occupation']; ?>" /></td>
</tr>
<tr>
<td colspan=2><div align="center"><input type="submit" name="submit" value="Update" /></div></td>
</tr>
</table>
</form><!-- End of Form -->
// Include the HTML footer file.
include_once ('incl/footer.html');