Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 1

PHP
<?php
include ('dbh.inc.php');

//commented out temporarily due to pathing issue
//require_once ('./assets/includes/update_item.inc.php')

//displays all errors or warnings
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


 $prodid = mysqli_real_escape_string($connection, $_POST[`prod-id`]);
 $brandid = mysqli_real_escape_string($connection, $_POST[`brand-id`]);
 $quantity = mysqli_real_escape_string($connection, $_POST[`quantity`]);
 $pointcost = mysqli_real_escape_string($connection, $_POST[`point-cost`]);
 $expirationdate = mysqli_real_escape_string($connection, $_POST[`expiration-date`]);
 $brandname = mysqli_real_escape_string($connection, $_POST[`brand-name`]);
 $producetype = mysqli_real_escape_string($connection, $_POST[`produce-type`]);
 
 if(mysqli_query($connection, "CALL upinventory(". $prodid . "," . $brandid . ",'" . $quantity . "'," . $pointcost . "," . $brandname . "," . $producetype . ");")){
 echo "Inventory updated.";
} else{
    echo "ERROR: Could not update $sql. " . mysqli_error($connection);
}

mysqli_close($connection);
?>


What I have tried:

tried different syntax's, but have no idea what to do from here
Posted
Updated 3-Apr-21 18:49pm
v4
Comments
Patrice T 3-Apr-21 18:24pm    
Do you understand that you forgot to show offending code ?
Arielle Alejo 3-Apr-21 21:14pm    
sorry, i did but when i kept uploading it, it would disappear, but its up now. thank you

First of all, for debugging purpose, change your code to:
PHP
echo "CALL upinventory(". $prodid . "," . $brandid . ",'" . $quantity . "'," . $pointcost . "," . $brandname . "," . $producetype . ");";
if(mysqli_query($connection, "CALL upinventory(". $prodid . "," . $brandid . ",'" . $quantity . "'," . $pointcost . "," . $brandname . "," . $producetype . ");")){

Then, you will see what is the real query matching the error message.
I suspect the single quotes are misplaced or missing, they must be around each alphabetic parameter.

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 
Basically more than one values are missing for number columns so you're getting multiple commas in your SQL query and that's why you're getting syntax error.

To avoid this use Parameterize SQL queries. As other answer said, it's useful to avoid SQL injection.

Here a simple example
PHP MySQL Prepared Statements[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900