I'm having issues placing a PHP variable in MySQL string,
<?php
$con=mysqli_connect("***","***","***","***");
function getItem($itemNo)
{
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM products WHERE product_id = '$itemNo'");
echo $itemNo;
echo "<br>";
while($row = mysqli_fetch_array($result))
{
echo $row['product_id'] . " " . $row['product_name'];
echo "<br>";
}
}
getItem(1001);
mysqli_close($con);
?>
The page shows my echo of the $itemNo
, but thats all. If I just do select * from products
, it gives my entire table like it should, so I know the database is working,
so I've narrowed it down to the placement of the variable.
EDIT:
product_id
column is an int and also the primary key.