Hello guyz. Can anyone help me with my insert script coz it always shown like this ERROR: Could not able to execute INSERT INTO ‘group’(tid,sid,code) VALUES (‘A’, ‘G’, ‘B’). You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘group’(tid,sid,code) VALUES (‘A’, ‘G’, ‘B’)’ at line 1.
Here is my code:
for insert.
<?php
session_start();
$link = mysqli_connect("localhost", "root", "", "authentication");
if (isset($_POST['button'])) {
// Check connection
if($link === false){
die("ERROR: Could not connect.".mysqli_connect_error());
}
// Escape user inputs for security
$tid = mysqli_real_escape_string($link, $_POST['tid']);
$sid = mysqli_real_escape_string($link, $_POST['sid']);
$code = mysqli_real_escape_string($link, $_POST['code']);
// attempt insert query execution
$sql = "INSERT INTO group(tid,sid,code) VALUES ('$tid', '$sid', '$code')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
// close connection
mysqli_close($link);
?>
group.php
<!DOCTYPE html>
<html>
<title></title>
<head>
<link rel="stylesheet" type="text/css" href="design.css">
</head>
<body>
<form action="insert.php" method="post">
<center>
<table width="200" border="0">
<tr>
<td width="92">Group</td>
<td width="92"><label for="textfield3"></label>
<input type="text" name="tid"required" /></td>
</tr>
<tr>
<td>Subject</td>
<td><label for="textfield4"></label>
<input type="text" name="sid" "required" /></td>
</tr>
<tr>
<td>Code</td>
<td><label for="textfield5"></label>
<input type="text" name="code" href="rand.php">
</tr>
<tr>
<td><input type="submit" name="button" id="button" value="submit" /></td>
<td> </td>
</tr>
</table>
</center>
</form>
thanks for the coming help!