Error: INSERT INTO 'student' ('student_num', 'last_name', 'first_name', 'middle_init') VALUES ('2018-03829', 'Cacayuran', 'Alexis', 'A')
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''student' ('student_num', 'last_name', 'first_name', 'middle_init') VALUES (...' at line 1
What I have tried:
PHP Code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "program_checklist";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error){
die("Connection failed: ".$conn->connect_error);
}
echo "Connected succesfully<br>";
$a = $_POST['studentnum'];
$b = $_POST['lastname'];
$c = $_POST['firstname'];
$d = $_POST['middleinit'];
$insertsql =
"INSERT INTO 'student' ('student_num', 'last_name', 'first_name', 'middle_init')
VALUES ('$a', '$b', '$c', '$d')";
if ($conn->query($insertsql) === TRUE){
echo "New record created succesfully";
}else{
echo "Error: ".$insertsql."<br>".$conn->error;
}
$conn->close();
?>
HTML Code
<!DOCTYPE html>
<html>
<head>
<title>Student Checklist</title>
</head>
<body>
<form action="submit.php" method="post">
Student Number:<br>
<input type="text" name="studentnum"><br>
Last Name:<br>
<input type="text" name="lastname"><br>
First Name:<br>
<input type="text" name="firstname"><br>
Middle Initial:<br>
<input type="text" name="middleinit"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>