Hi guys. Im trying to create a page where clients (once logged in) can update their name, email or mobile number and this information should then be recorded in the database. The page looks right but when I press submit nothing happens. The information stays in the field and doesn’t get transferred to the database.
I am using webmatrix. Any help would be appreciated.
The code I have thus far is:
<?php # Script update_details.php
// This page lets a user change their details.
// Start the session
session_start();
$page_title = 'Update Your Details';
include ('includes/header.html');
// If no user_id is present, redirect the user:
if(empty($_SESSION['user_id'])) {
// Need the functions:
require('includes/login_functions.inc.php');
redirect_user();
}
// Check for form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require ('../mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
if(empty($_SESSION['first_name']))
$fn=$_POST['first_name'];
if(empty($_SESSION['last_name']))
$ln=$_POST['last_name'];
if(empty($_SESSION['email']))
$e=$_POST['email'];
if(empty($_SESSION['mobile']))
$m=$_POST['mobile'];
}
if ($check) { // OK!
if (empty($errors)){ // If everything’s OK.
// Check
$q = "SELECT user_id FROM users WHERE first_name='".$fn."', last_name='".$ln."', email='".$e."', mobile='".$m."'";
$r = mysqli_query($dbc, $q);
// Get the user_id:
$row = mysqli_fetch_array($r, MYSQLI_NUM);
// Make the UPDATE query:
$q = "UPDATE users SET email='".$e."', WHERE user_id=".$row[0];
$q = "UPDATE users SET first_name='".$fn."', WHERE user_id=".$row[0];
$q = "UPDATE users SET last_name='".$ln."', WHERE user_id=".$row[0];
$q = "UPDATE users SET mobile='".$m."', WHERE user_id=".$row[0];
$r = mysqli_query($dbc, $q);
if ($r) { // If it ran OK.
// Print a message.
echo '
Thank you!
';
echo '
Your details been updated!
';
}
mysqli_close($dbc); // Close the database connection.
// Include the footer and quit the script (to not show the form).
include ('includes/footer.html');
}
// Public message:
echo '
System Error
';
echo '
Your details could not be updated due to a
system error. We apologize for any inconvenience.
';
}
mysqli_close($dbc); // Close the database connection.
// End of the main Submit conditional.
?>
Update Your Details
Email Address:
<p>First Name: <input type="text" name="first_name" size="20"
maxlength="60" value="<?php if (isset($_POST['first_name'])) echo $_POST
['first_name']; ?>" /> </p>
<p>Last Name: <input type="text" name="last_name" size="20"
maxlength="60" value="<?php if (isset($_POST['last_name'])) echo $_POST
['last_name']; ?>" /> </p>
<p>Mobile: <input type="text" name="mobile" size="20"
maxlength="60" value="<?php if (isset($_POST['mobile'])) echo $_POST
['mobile']; ?>" /> </p>
<p><input type="submit" name="submit" value="Update"/></p>
<?php include ('includes/footer.html'); ?>