Jump to content

Recommended Posts

I'm having a problem with my second query. I've included the PHP around it as it might help to see what I'm trying to do.

$sql = "SELECT quantity, sku FROM ItemsOrdered
	        WHERE orderID = '$_POST[orderID]'";
	$result = mysqli_query($cxn, $sql)
	          or die ("Couldn't execute query 1.");
	$rowname = mysqli_fetch_assoc($result);
        extract ($rowname);

	$sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity')
	        WHERE sku = '$sku'";
	$result2 = mysqli_query($cxn, $sql2)
                  or die ("Couldn't execute query 2.");

Can someone see what the problem is? I think it has to do with the quantity = (quantity + '$quantity') part.

Link to comment
https://forums.phpfreaks.com/topic/181960-solved-query-problem/
Share on other sites

I keep getting the error "Couldn't execute query 2." which is why I think there's a problem with my query 2 syntax. I've tried these four changes to the query:

 

$sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity')
              WHERE sku = '$sku'";
$sql2 = "UPDATE Stock SET quantity = quantity + '$quantity'
              WHERE sku = '$sku'";
$sql2 = "UPDATE Stock SET quantity = quantity + $quantity
              WHERE sku = '$sku'";
$sql2 = "UPDATE Stock SET quantity = (quantity + $quantity)
              WHERE sku = '$sku'";

 

It just won't work at all. The only other thing I can think of is that maybe the PHP before it is wrong, but I can't see an error in that either.

Link to comment
https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960704
Share on other sites

please change this

 

$result2 = mysqli_query($cxn, $sql2)
                  or die ("Couldn't execute query 2.");

 

to

$result2 = mysqli_query($cxn, $sql2)
                  or die ("Couldn't execute query 2:".mysql_error());

 

for a better error description once you done that you should have the exact error and it will enable us to debug your code

Link to comment
https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960834
Share on other sites

Oh, I didn't even notice that. Here's the output:

 

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/nabira/chelbig/adelaidebooks/receipt.php on line 23

Couldn't execute query 2.

 

Line 23 is:

or die ("Couldn't execute query 2.".mysqli_error());

Link to comment
https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960881
Share on other sites

Oh gotcha. Here's the new error message:

 

Couldn't execute query 2. Unknown column 'quantity' in 'field list'.

 

And I think I just figured it out myself. The column is named quantity in ItemsOrdered, but it's quantityOnHand in Stock. Gah.

 

Thanks so much for your help, I can't believe I made such a stupid error.

Link to comment
https://forums.phpfreaks.com/topic/181960-solved-query-problem/#findComment-960892
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.