Below is the HTML form which takes input subject & beginner(yes,no) from user and inserts it into database
<form action="coursesignup.php" method="post">
Select Subject:<br>
<select name="subject">
<option value="select" selected>select</option>
<option value="Database Management Systems">Database Management Systems</option>
<option value="Advanced Microprocessors">Advanced Microprocessors</option> </select><br><br>
Are you a Beginner:<br>
<select name="beginner">
<option value="select" selected>select</option>
<option value="yes">yes</option>
<option value="no">No</option></select><br><br>
<input type="submit" value="Submit" /></form>
Form submits the data into following php file. However, it is not inserting the values at the respective userid but putting them at the end of the table
<?php
session_start();
if($_SESSION["username"])
$_POST["username"]=$_SESSION["username"];
$user=$_POST["username"];
// Check connection
$con=mysqli_connect("localhost","root","","elearning");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$subject = mysqli_real_escape_string($con, $_POST['subject']);
$beginner= mysqli_real_escape_string($con, $_POST['beginner']);
$sql=" UPDATE student_info SET subject=$subject AND beginner=$beginner
WHERE username=$user " ;
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Successfuly entered";
mysqli_close($con);
?>
It gives following error:
Error: Erreur de syntaxe près de 'Management Systems AND ;beginner=yes WHERE username=gk4316' à la ligne 1