You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

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>&nbsp;</td>
        </tr>
      </table>
    </center>
  </form>

thanks for the coming help!

I don’t think you should have single quotes around the variables, should you?

It would make things easier if the error message matched your posted code. In particular, the error message shows back ticks around group while the php code does not. Copy/paste is often useful for these sort of things.

Sorry. I’m new to php. I just need help :).

Can you make an appropriate code for this sir? :smile:

already tried. Not working :slight_smile:

At this point, I’m guessing you are randomly trying possible and that you have lost track of what you are doing. Your error message does not match your code. Making it pretty much impossible to help you.

And by the way, if your professor is saying to use things like:

$sql = "INSERT INTO group(tid,sid,code) VALUES ('$tid', '$sid', '$code')";

Then drop out of the class and try to get your money back.

You should be validating the user submitted data before it gets anywhere near the database. Also you should have a read up about prepared statements

INSERT INTO what table?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.