PHP不将变量插入mySQL查询

I am having trouble getting one of my variable to be successfully inserted into my mySQL query. Here is the query string:

$strShipMethodInfo = "SELECT BAMMDD, BAYY, BAXXX, ORDNUM, SHPNUM, \"SHIPMENT METHOD\", \"SHIPMENT STATUS\" FROM SHPPMTHD WHERE BAMMDD = " . $BAMMDD . " AND BAYY = " . $BAYY . " AND BAXXX = " . $BAXXX . " AND SHPNUM = " . $arrShippingInfo[$x]['SHPNUM'] . " AND ORDNUM = '" . $ORDNUM . "' ORDER BY SHPNUM";

I am using $arrShippingInfo[$x]['SHPNUM'] in another query that is very similar, and it is putting the variable in that one. However, when I do it with this query, it comes back as blank. All the other values (BAMMDD, BAYY, BAXXX, etc.) are successfully put in, but the variable for SHPNUM does not get put in.

I have tried everything I can think of, thinking that it might be a quote in the wrong place, but I have been unsuccessful. Could anyone please help me figure this out? Thanks.

EDIT: I did a print_r on the string, and it printed twice... once with the SHPNUM correctly inserted and once with it blank. Turns out it was a logic error in the for loop I was using (I needed to run the query for each shipment in the order). < somehow got changed to <= so once I changed that it worked. Thank you everyone for your responses.

I would say there is something wrong with how you are accessing that array value, either with the $x variable, or in how you are passing in the raw array value to the string (hard to say without the rest of your code: try assigning it to $SHPNUM and putting $SHPNUM into the statement?).

Within your code try running an:

echo $x; echo $arrShippingInfo[$x]['SHPNUM'];
var_dump($arrShippingInfo);

and you should be able to find the issue.

Using dummy data with your statement and running that code through on my end as:

<?php

$BAMMDD = 'bamddd';
$BAYY = 'BAYY';
$BAXXX = 'BAXXX';
$arrShippingInfo[0]['SHPNUM'] = '54';
$ORDNUM = 555;

$x = 0;
$strShipMethodInfo = "SELECT BAMMDD, BAYY, BAXXX, ORDNUM, SHPNUM, \"SHIPMENT METHOD\", \"SHIPMENT STATUS\" FROM SHPPMTHD WHERE BAMMDD = " . $BAMMDD . " AND BAYY = " . $BAYY . " AND BAXXX = " . $BAXXX . " AND SHPNUM = " . $arrShippingInfo[$x]['SHPNUM'] . " AND ORDNUM = '" . $ORDNUM . "' ORDER BY SHPNUM";

echo "<pre>$strShipMethodInfo</pre>";
?>

Produces:

SELECT BAMMDD, BAYY, BAXXX, ORDNUM, SHPNUM, "SHIPMENT METHOD", "SHIPMENT STATUS" FROM SHPPMTHD WHERE BAMMDD = bamddd AND BAYY = BAYY AND BAXXX = BAXXX AND SHPNUM = 54 AND ORDNUM = '555' ORDER BY SHPNUM

$strShipMethodInfo = "SELECT BAMMDD, BAYY, BAXXX, ORDNUM, SHPNUM, \"SHIPMENT METHOD\", \"SHIPMENT STATUS\" FROM SHPPMTHD WHERE BAMMDD = '" . $BAMMDD . "' AND BAYY = '" . $BAYY . "' AND BAXXX = '" . $BAXXX . "' AND SHPNUM = '" . $arrShippingInfo[$x]['SHPNUM'] . "' AND ORDNUM = '" . $ORDNUM . "' ORDER BY SHPNUM";

Added quotes(') in the where condtion