I want to know if i can use mysql_query() return type boolean to determine the output of my program.
for example I have a program that inserts a product or products into the database. I want mysql to look and see if there is a product with the same name something like below
if (!mysql_query($sql,$ok))
{
while ($row = mysql_fetch_assoc($results))
{
if ($numRows != 4)
{
$sql = "INSERT INTO storeFront
(sfName,sfPic,sfPrice,productID)
VALUE
('{$row['productName']}','{$row['productPic']}',
'{$row['productPrice']}','{$row['ProductID']}')";
mysql_query($sql,$ok);
} else { echo 'There is too many products in the Store Front! only 4 allowed!';}
}
} else {echo 'That product is already in there!';}
it checks to see if it can find the product, if it doesnt then it inserts a new product into the database. if it does return something then it says there is too many products in the storefront. only 4 allowed
in the PHP manual, it says that it returns FALSE if it doesnt return a resource. could I do something like
If (mysql_query($sql,$ok) =="FALSE")
{
insert a new product;
}
if it doesnt find the product then insert the product.
I want to do it this way cause to me, i feel it will save me alot of programming time.