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..

Have you tried it with a space before and after the = signs?

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...:)

1.

if(isset($_POST["btnDelete"])){
 
	$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());
	unlink($image2);
	header('Location: ../categories.php');
	
}

2.

foreach($_POST['status'] as $index){
			if(isset($_POST["btnAccept"])){
				$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:

<?php
    $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);
    ?>

INSERT INTO does not have a WHERE clause, unless you are inserting from another table.

@rch1231,

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

@pritaeas,

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

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..:(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.