I want to reset a database table id by the SQL command in PHP when I click a button but unfortunately, the SQL command work on the PHPmyadmin SQL option, not working in PHP.
I am getting the 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 'UPDATE wordmeanings_table SET id = @num := (@num+1); ALTER TABLE wordmeanings...' at line 1 in E:\xampp\htdocs\php-ajax\index.php:98 Stack trace: #0 E:\xampp\htdocs\php-ajax\index.php(98): mysqli_query(Object(mysqli), 'SET @num := 0;...') #1 {main} thrown in E:\xampp\htdocs\php-ajax\index.php on line 98
Check out the PHP codes, I don't know what's wrong with the codes:
<?php
if(isset($_POST['submit']))
{
$sql = "SET @num := 0; UPDATE wordmeanings_table SET id = @num := (@num+1); ALTER TABLE wordmeanings_table AUTO_INCREMENT =1";
mysqli_query($conn, $sql);
};
?>