I'm using the following code to add a row of data into a MySQL database. I'm getting an odd error though. The error suggests I'm trying to add data into a column that doesn't exist called "Nathan", but that's the value of $fName
. Is VALUES
not where I put the data that I want inserted into the table? Heres my relevant code, thanks!
// Create connection
$conn = new mysqli($servername, $username, $password, $username);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
//Column names are FIRSTNAME, LASTNAME, TEACHERNAM, MSIPROOM
$sql = "INSERT INTO PerA (FIRSTNAME, LASTNAME, TEACHERNAME, MSIPROOM) VALUES ($fName, $lName, $tName, $mRoom)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}