Hi, I have written a script to update customer details. At the moment I retrieve customer details from the database and display them within the relevant text fields. I then want to change the appropriate data and update the database so the new data is stored. The update works but the problem is, the original value retrieved from the database is saved and not the value changed in the text field. If anyone could help I would be very grateful!!!
Update code and one text field code:
if (!isset($_SESSION['customer_id'])) {
header ("Location: <a href="http://" target="_blank">[url]http://[/url]</a>" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean();
exit();
} else {
if (isset($_POST['submit'])) { // Handle the form.
require ('../mysql_connect.php'); // Connect to the database.
// Check for an email address.
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>';
}
// Check for addr1:
if (strlen($_POST['addr1']) > 0) {
$a1 = stripslashes($_POST['addr1']);
} else { // If no addr1 was entered...
$a1 = NULL;
echo '<p><b>You forgot to enter your address!</b></p>';
}
// Check for addr2:
if (strlen($_POST['addr2']) > 0) {
$a2 = stripslashes($_POST['addr2']);
} else { // If no postcode was entered...
$a2 = NULL;
echo '<p><b>You forgot to enter your address!</b></p>';
}
//addr3:
{
$a3 = stripslashes($_POST['addr3']);
}
//addr4:
{
$a4 = stripslashes($_POST['addr4']);
}
// Check for a postcode.
if (eregi ("^[[:alnum:]]{6,}$", stripslashes(trim($_POST['postcode'])))) {
$pc = escape_data($_POST['postcode']);
} else {
$pc = FALSE;
echo '<p><font color="red" size="+1">Please enter your postcode!</font></p>';
}
//telephone:
{
$te = stripslashes($_POST['telephone']);
}
if ($e && $a1 && $a2 && $pc && $te) { // If everything's OK.
// Make the query.
$query = "UPDATE customer SET (email, addr1, addr2, addr3, addr4, postcode, telephone) VALUES ('$e', '$a1', '$a2', '$a3', '$a4', '$pc', '$te') WHERE customer_id={$_SESSION['customer_id']}";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() != 0) { // If it ran OK.
// Send an email, if desired.
echo '<h3>Your details have been changed.</h3>';
include ('includes/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo "<p><font color='red' size='+1'>Your details could not be changed due to a system error. We apologize for any inconvenience.</font></p>";
}
mysql_close(); // Close the database connection.
} else { // Failed the validation test.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}
} else { // Display the form. // End of the main Submit conditional.
require ('../mysql_connect.php'); // Connect to the database.
?>
<?php // Retrieve the addr4 and add to field.
$sql = "SELECT addr1 FROM customer WHERE customer.customer_id = {$_SESSION['customer_id']}";
$result = @mysql_query($sql) or die("Couldn't execute query!");
while ($row = mysql_fetch_array($result)) {
$addr1 = $row['addr1'];
echo "<input type='text' name='addr1' size='40' maxlength='40' value='$addr1'>";
}
?>