I haven't been able to get my INSERT statement to work. I know the problem is how I'm trying to bind the parameters. INSERT was working before I added parameter binding.
$inventoryQuery = "INSERT INTO inventory (Whse, Product, Description,
QtyOnHand, QtyUnavail, BinLoc1, BinLoc2, GLCost, OnhandTotalValue,
UnavailTotalValue, GrandTotalValue)
VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?');";
// execute INSERT statement
$conn = $GLOBALS['conn'];
$stmt = $conn->prepare($inventoryQuery);
$stmt->bindParam(1, $sqlV[0]);
$stmt->bindParam(2, $sqlV[1]);
$stmt->bindParam(3, $sqlV[2]);
$stmt->bindParam(4, $sqlV[3]);
$stmt->bindParam(5, $sqlV[4]);
$stmt->bindParam(6, $sqlV[5]);
$stmt->bindParam(7, $sqlV[6]);
$stmt->bindParam(8, $sqlV[7]);
$stmt->bindParam(9, $sqlV[8]);
$stmt->bindParam(10, $sqlV[9]);
$stmt->bindParam(11, $sqlV[10]);
$stmt->execute();
Output using var_dump($stmt):
object(PDOStatement)[2] public 'queryString' => string 'INSERT INTO inventory (Whse,Product,Description,QtyOnHand,QtyUnavail,BinLoc1,BinLoc2,GLCost,OnhandTotalValue,UnavailTotalValue,GrandTotalValue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);' (length=192)
I have seen and tried many ways to handle binding parameters. And now my head is swimming. If you could provide a solution and an explanation, I would be so happy.
Solution from all info provided:
try{
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$inventoryQuery = "INSERT INTO inventory ($sqlField)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
// execute INSERT statement
$conn = $GLOBALS['conn'];
$stmt = $conn->prepare($inventoryQuery);
$stmt->bindValue(1, $sqlV[0]);
$stmt->bindValue(2, $sqlV[1]);
$stmt->bindValue(3, $sqlV[2]);
$stmt->bindValue(4, ((int) ((float) $sqlV[3])));
$stmt->bindValue(5, ((int) ((float) $sqlV[4])));
$stmt->bindValue(6, $sqlV[5]);
$stmt->bindValue(7, $sqlV[6]);
$stmt->bindValue(8, ((float) $sqlV[7]));
$stmt->bindValue(9, ((float) $sqlV[8]));
$stmt->bindValue(10, ((float) $sqlV[9]));
$stmt->bindValue(11, ((float) $sqlV[10]));
$stmt->execute();
}
catch(PDOException $ex){
var_dump($ex);
}
Thanks to everyone that helped!
$sqlVare being populated from. In the meantime, try anarraymethod$stmt->execute(array($sqlV[0], $sqlV[1]), etc.);