Reputation: 43
As a customer, I have no problem in displaying my details/profile but I can't update/edit my profile even though I have clicked the "Save" button. Am I missing something here?
edit_customer_profile.php
<?php
header('Content-Type: text/html; charset=utf-8');
include 'connection.php';
session_start();
if(isset($_SESSION['CustomerID'])) {
$customerID = $_SESSION['CustomerID'];
$customername = $_SESSION['CustomerName'];
$customers = mysql_query("select * from customer where CustomerID='".$customerID."'");
$customer = mysql_num_rows($customers);
if($customer== 1){
$row = mysql_fetch_assoc($customers);
$email = $row['CustomerEmail'];
$contactno = $row['CustomerContactNo'];
$class = $row['CustomerClass'];
$campus = $row['CustomerCampus'];
$intake = $row['CustomerIntake'];
if(isset($_POST['submit'])){
$_var1 = $_POST['new_name'];
$_var2 = $_POST['new_email'];
$_var3 = $_POST['new_contactno'];
$_var4 = $_POST['new_campus'];
$_var5 = $_POST['new_intake'];
$_var6 = $_POST['new_class'];
$query1 = "UPDATE customer
SET CustomerName='$_var1', CustomerEmail='$_var2', CustomerContactNo='$_var3', CustomerCampus='$_var4', CustomerIntake='$_var5', CustomerClass='$_var6'
WHERE CustomerID='$customerID'";
}
}
}
?>
Below is the form
<form method = "post" action=">
<tr>
<td width="170">Name:</td>
<td><input type="text" name="new_name" size="30" value="<?php echo $customername ?>" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="new_email" size="30" value="<?php echo $email ?>" /></td>
</tr>
<tr>
<td>Contact No:</td>
<td><input type="text" name="new_contactno" size="30" value="<?php echo $contactno ?>" /></td>
</tr>
<tr>
<td>Campus:</td>
<td><input type="text" name="new_campus" size="30" value="<?php echo $campus ?>" /></td>
</tr>
<tr>
<td>Intake:</td>
<td><input type="text" name="new_intake" size="30" value="<?php echo $intake ?>" /></td>
</tr>
<tr>
<td>Class:</td>
<td><input type="text" name="new_class" size="30" value="<?php echo $class ?>" /></td>
</tr>
<tr>
<td align="right"><input type="submit" size="30" name="submit" value="Save" /></td>
</tr>
</form>
Upvotes: 2
Views: 107
Reputation: 3382
You haven't run the update query.
Run your update query with
$query1 = "UPDATE customer
SET
CustomerName='$_var1',
CustomerEmail='$_var2',
CustomerContactNo='$_var3',
CustomerCampus='$_var4',
CustomerIntake='$_var5', CustomerClass='$_var6'
WHERE CustomerID='$customerID'";
mysql_query($query1);
Note: Use mysqli_* or pdo_* functions instead of mysql_ functions, which is going to deprecated.
Upvotes: 1