Chris K.

asked • 03/25/19

Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax t

<?php

session_start();

require('connect.php');


if(isset($_POST['submit'])){


$id = $_POST['id'];

$username = $_POST['username'];

$name = $_POST['name'];

$email = $_POST['email'];

$password = md5($_POST['password']);

$dob = $_POST['dob'];

$gender = $_POST['gender'];

$location = $_POST['location'];

$course = $_POST['course'];

$mobile = $_POST['mobile'];


$sql = " UPDATE user SET username =['$username'], name = ['$name'], email = ['$email'], password=['$password'], dob = ['$dob'], gender =['$gender'],location =['$location'], course = ['$course'], mobile = ['$mobile'] WHERE id= $id ";

if (mysqli_query($mysqli, $sql)) {

$smsg = "Record updated successfully";

} else {

$fmsg = "Error updating record: " . mysqli_error($mysqli);

}

}

?>

<html>

<head>

<title>User Registration PHP & MYSQL</title>



<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >


<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap-theme.min.css" >

<link rel="stylesheet" href="styles.css" >



<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>


</head>

<body>

<div class="container">

<a class= "float-right" href = "logout.php"> LOGOUT </a>

<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>

<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>

<form class="form-signin" method="POST">

<h2 class="form-signin-heading">Edit Profile</h2>

<div class="input-group">

<input type="hidden" name="id" placeholder="ID">

<input type="text" name="username" class="form-control" placeholder="username" required></div>


<label for="inputname" class="sr-only">Full Name</label>

<input type="text" name="name" id="inputname" class="form-control" placeholder="Full Name"required>


<label for="inputEmail" class="sr-only">Email address</label>

<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address"required>

<label for="inputPassword" class="sr-only">Password</label>

<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>

<label for="inputDoB" class="sr-only">DOB</label>

<input type="date" name="dob" id="inputDoB" class="form-control" placeholder="DOB"required>


<td>Gender:</td>

<input type="radio" name="gender" value="m">Male

<input type="radio" name="gender" value="f">female

</tr>

<label for="inputlocation" class="sr-only">Location</label>

<input type="text" name="location" id="inputlocation" class="form-control" placeholder="Location"required>


<label for="inputcourse" class="sr-only">Course</label>

<input type="text" name="course" id="inputcourse" class="form-control" placeholder="Course" required>


<label for="inputmobile" class="sr-only">Mobile</label>

<input type="text" name="mobile" id="inputmobile" class="form-control" placeholder="Mobile" required>

<button class="btn btn-lg btn-primary btn-block" type="submit" name="submit">Update</button>

</div>

</body>

</head>

</html>

1 Expert Answer

By:

ROMANUS O. answered • 05/24/22

Tutor
New to Wyzant

I'm Romanus A web developer with several years of experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.