Im getting an sql error saying "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 '' at line 1"

These are the 2 queries...

$sql = "DELETE FROM tbl_category WHERE cat_id=$cid";

$sql2="INSERT INTO tbl_sales (order_id,customer_id) VALUES ($row[order_id],$row[cus_id]) WHERE order_id='$index'";

Cannot figure it out whats wrong? can some one help me please..

7 Years
Discussion Span
Last Post by sami.asanga

yeah..tried it in that way too...:(

but same error is continuously appearing...is it something because of the variables which I have used??


Your missing single quotes around $cid

cat_id = '$cid' ";

I think. Can you post the whole script or attach it as a file?


yaa...this is it...:)


	$cid         = $_POST['catId'];
	$name3       = $_POST['txtName'];
	//$image3		 = $_POST['file'];
	//Remove the product from the database
	$sql    = "DELETE FROM tbl_category WHERE cat_id = '$cid'";
	$result2 = mysql_query($sql) or die(mysql_error());
	header('Location: ../categories.php');


foreach($_POST['status'] as $index){
				$sql2="INSERT INTO tbl_sales (order_id,customer_id) VALUES ($row[order_id],$row[cus_id]) WHERE order_id = '$index'";
			$result2=mysql_query($sql2) or die(mysql_error());

Best thing I can think of at the moment is to give your the script I used to create my deletions:

    $mysqli = new mysqli("localhost", "catalog_user", "secret", "catalog_prod");
    // Create the query
    $query = "DELETE FROM products WHERE sku = 'TY232278'";
        // Send the query to MySQL
        $result = $mysqli->query($query, MYSQLI_STORE_RESULT);
        // Tell the user how many rows have been affected
        printf("%d rows have been deleted.", $mysqli->affected_rows);


You are code seems to be unclear for me..:(


ohh is that so..But I need to insert the order which are accepted by the admin to the sales table..Then how should I do it?? Can you please help me..


Maybe you replace INSERT by something like this:

update products set quantity = quantity - quvalue_from_admin_list 
  where id_quantity = idvalue_from_admin_list

This would somewhat coincide with your other posting.

I have assumed that your admin's list is a sales list, therefore quantities on stock must be reduced by sold amounts.

-- tesu

Edited by tesuji: n/a


yaa may be related because the same system am talking about..:)
but what i said here is both insert and delete queries which I used is giving me an error...

And cannot use update here right?? because I need to insert the entries to a separate table ...

Btw Thanks all for you are replies..But the problem is still same..:(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.