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 'WHERE SET numb='61' WHERE ID='#ID'' at line 1 in C:\xampp\htdocs\web_2.1\php\send.php:20 Stack trace: #0 C:\xampp\htdocs\web_2.1\php\send.php(20): mysqli_query(Object(mysqli), 'UPDATE depo...') #1 {main} thrown in C:\xampp\htdocs\web_2.1\php\send.php on line 20
I trying to add numbers in mysql database, for example:
session_start();
include('info.php');
$add = $_POST['submit'];
$ID=$_SESSION['ID'];
$query="SELECT numb FROM `prof` WHERE ID='$ID'";
$result=mysqli_query($conn, $query);
$pr=mysqli_num_rows($result);
if($pr>0){
$row=mysqli_fetch_array($result);
$i=$row['numb'];
$total = $i $add;
$querys="UPDATE `prof` WHERE SET numb='$total' WHERE ID='$ID'";
$result=mysqli_query($conn, $querys);
header("Location: send.php");
} else{
$sql="INSERT INTO `prof` (ID, numb)VALUES($ID, $add)";
$result=mysqli_query($conn, $sql);
header("Location: /web_2.1/profile.php");
}
but after sending first query I can't send second one and getting this error
CodePudding user response:
Try with below query string
$querys = "UPDATE `prof` SET numb='$total' WHERE ID='$ID'";
CodePudding user response:
This query has two WHERE keywords, that is not valid SQL, there can only be one WHERE:
$querys="UPDATE prof WHERE SET numb='$total' WHERE ID='$ID'";
What you are looking for seems to be an AND condition, replacing the 2nd WHERE with an AND keyword instead:
$querys="UPDATE prof WHERE SET numb='$total' AND ID='$ID'";