I have edited this page from a free template and i want it to update a table in a mysql db, it shows the row i want and the data is correct but when i try to update it just deletes the existing content and does not update…If anyone is kind enough to give me a steer i would really appreciate it thank you, code below, oh and please make it simple i am just a pensioner trying to get to grips with php…
<?php
session_start();
include("connection.php");
if (!isset($_SESSION['username'])) {
header("location: login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Profile</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<link rel="stylesheet" href="css/style1.css">
</head>
<body>
<div class="container">
<div class="form-box box">
<?php
if (isset($_POST['update'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$id = $_SESSION['id'];
$edit_query = mysqli_query($conn, "UPDATE individual SET username='$username', email='$email', password='$password', contactno='$contactno', firstname='$firstname', lastname='$lastname', postcode='$postcode', aline1='$aline1', aline2='$aline2', county='$county', country='$country' ,qualifications='$qualifications', dob='$dob', workwanted='$workwanted', skills='$skills', available='$available', driver='$driver', volunteer='$volunteer', parttime='$parttime', fulltime='$fulltime' , maxtravelradius='$maxtravelradius', specialneeds='$specialneeds', fitnesslevel='$fitnesslevel', notes='$notes', nationality='$nationality', gender='$gender' WHERE id = $id");
if ($edit_query) {
echo "<div class='message'>
<p>Profile Updated!</p>
</div><br>";
echo "<a href='home.php'><button class='btn'>Go Home</button></a>";
}
} else {
$id = $_SESSION['id'];
$query = mysqli_query($conn, "SELECT * FROM individual WHERE id = $id") or die("error occurs");
while ($result = mysqli_fetch_assoc($query)) {
$res_username = $result['username'];
$res_email = $result['email'];
$res_password = $result['password'];
$res_id = $result['id'];
$res_contactno = $result['contactno'];
$res_firstname = $result['firstname'];
$res_lastname = $result['lastname'];
$res_postcode = $result['postcode'];
$res_aline1 = $result['aline1'];
$res_aline2 = $result['aline2'];
$res_county = $result['county'];
$res_country = $result['country'];
$res_qualifications = $result['qualifications'];
$res_dob = $result['dob'];
$res_workwanted = $result['workwanted'];
$res_skills = $result['skills'];
$res_available = $result['available'];
$res_driver = $result['driver'];
$res_volunteer = $result['volunteer'];
$res_parttime = $result['parttime'];
$res_fulltime = $result['fulltime'];
$res_maxtravelradius = $result['maxtravelradius'];
$res_specialneeds = $result['specialneeds'];
$res_fitnesslevel = $result['fitnesslevel'];
$res_notes = $result['notes'];
$res_nationality = $result['nationality'];
$res_gender = $result['gender'];
}
?>
<header>Update Profile</header>
<form action="#" method="POST" enctype="multipart/form-data">
<div class="form-box">
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Username" name="username"
value="<?php echo $res_username; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-envelope icon"></i>
<input class="input-field" type="email" placeholder="Email Address" name="email"
value="<?php echo $res_email; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-lock icon"></i>
<input class="input-field password" type="password" placeholder="Password" name="password"
value="<?php echo $res_password; ?>" required>
<i class="fa fa-eye toggle icon"></i>
</div>
<div class="input-container">
<i class="fa fa-lock icon"></i>
<input class="input-field password" type="text" placeholder="ID Number" name="id"
value="<?php echo $res_id; ?>" required>
<i class="fa fa-eye toggle icon"></i>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Contact Number" name="contactno"
value="<?php echo $res_contactno; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="First Name" name="firstname"
value="<?php echo $res_firstname; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Last Name" name="lastname"
value="<?php echo $res_lastname; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Postcode" name="postcode"
value="<?php echo $res_postcode; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="First line address" name="aline1"
value="<?php echo $res_aline1; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Second line address" name="aline2"
value="<?php echo $res_aline2; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="County" name="county"
value="<?php echo $res_county; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Country" name="country"
value="<?php echo $res_country; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Qualifications" name="qualifications"
value="<?php echo $res_qualifications; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Date of Birth" name="dob"
value="<?php echo $res_dob; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Work wanted" name="workwanted"
value="<?php echo $res_workwanted; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Skills" name="skills"
value="<?php echo $res_skills; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Availability" name="available"
value="<?php echo $res_available; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Driver Y/N" name="driver"
value="<?php echo $res_driver; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Volunteer Y/N" name="volunteer"
value="<?php echo $res_volunteer; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Parttime" name="parttime"
value="<?php echo $res_parttime; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Full Time Y/N" name="fulltime"
value="<?php echo $res_fulltime; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Max Travel Radius" name="maxtravelradius"
value="<?php echo $res_maxtravelradius; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Special Needs Y/N" name="specialneeds"
value="<?php echo $res_specialneeds; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Fitness Level 1-10" name="fitnesslevel"
value="<?php echo $res_fitnesslevel; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Notes" name="notes"
value="<?php echo $res_notes; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Nationality" name="nationality"
value="<?php echo $res_nationality; ?>" required>
</div>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Gender" name="gender"
value="<?php echo $res_gender; ?>" required>
</div>
</div>
<div class="field">
<input type="submit" name="update" id="submit" value="Update" class="btn">
</div>
</form>
</div>
<?php } ?>
</div>
<script>
const toggle = document.querySelector(".toggle"),
input = document.querySelector(".password");
toggle.addEventListener("click", () => {
if (input.type === "password") {
input.type = "text";
toggle.classList.replace("fa-eye-slash", "fa-eye");
} else {
input.type = "password";
}
})
</script>
</body>
</html>