-5

here is the full error

Fatal error: Uncaught mysqli_sql_exception: 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 ':' at line 4 in C:\xampp\htdocs\food-order\Backend\add-admin.php:62 Stack trace: #0 C:\xampp\htdocs\food-order\Backend\add-admin.php(62): mysqli_query(Object(mysqli), 'INSERT INTO tb...') #1 {main} thrown in C:\xampp\htdocs\food-order\Backend\add-admin.php on line 62.

Here is the SQL code

 // Execute the query and Save data into database
    $conn = mysqli_connect('localhost', 'root', '') or  die(mysqli_error($conn));

    $db_select = mysqli_select_db($conn, 'food-order') or die(mysqli_error($conn));

    $res = mysqli_query($conn, $sql) or die(mysqli_error($conn));
}
?>

the $res code seems to be the one with the syntax error but i cannot find it

ADyson
  • 51,527
  • 13
  • 48
  • 61
Beasta
  • 1
  • 1
  • 3
    "Here is the SQL code" — No. You have a variable called `$sql` but you didn't include how you populated in the question. – Quentin May 31 '22 at 07:58
  • 1
    The error is in the ***`$sql` query***, not the PHP code. – deceze May 31 '22 at 07:59
  • 1
    A clue to that is that the error message says **near ':'** and you don't have a `:` in the code you shared. – Quentin May 31 '22 at 08:02
  • A general tip, improve your error handling to make it less verbose - see [mysqli or die, does it have to die?](https://stackoverflow.com/questions/15318368/mysqli-or-die-does-it-have-to-die). Also, `mysqli_error` doesn't detect connection errors - after all it requires a valid connection object to be passed into it, so logically how could it possibly do that? – ADyson May 31 '22 at 08:07
  • @ADyson well, thanks to our Dharman, nowadays mysqli just doesn't pay much attention to this or die stuff. So although it's being utterly useless, it does no harm either. – Your Common Sense May 31 '22 at 08:43
  • @YourCommonSense agreed, but the point was to highlight to the OP that they're not going to properly detect any connectivity problems that way. Obviously as you say with the latest PHP versions the mysqli errors are on automatically so it's less of an issue. – ADyson May 31 '22 at 08:44

0 Answers0