I am developing a php program. I can not make this code work:
$ref="demo_3";
$ident=comprobarExisteProd($ref);
function comprobarExisteProd ($refer)
{
$id_product=0;
$sqlpr = 'SELECT * FROM `'._DB_PREFIX_.'product` WHERE `reference`=(string)$refer';
$res = Db::getInstance()->executeS($sqlpr);
var_dump($res);
echo "<br>";
if (!$res){
echo "The product does not exist in database";
echo "<br>";
} else{
$id_product=$res[0]['id_product'];
$precio=$res[0]['price'];
echo "The product exist with identifier: : ";
echo $id_product;
echo "<br>";
echo "The product price is: ";
echo $precio;
echo "<br>";
}
return id_product;
}
However, if I change:
$sqlpr = 'SELECT * FROM `'._DB_PREFIX_.'product` WHERE `reference`=(string)$refer';
with this other:
$sqlpr = 'SELECT * FROM `'._DB_PREFIX_.'product` WHERE `reference`="demo_3"';
Then the code works correctly.
How can I use the function comprobarExisteProd($refer)
using the parameter $refer
?
I have changed the code many times, but it does not work.