Reputation: 11
I am facing problem that driving me crazy, I wrote a PHP script that contains a javascript alert .the insertion of the item perform perfectly, but the alert message doesn't appear :(
here is my code
<?php
if ($city=="jeddah" && $catid=="2")
{
$conTL1->autocommit(false);
$error =array();
$q3= $conTL2->query("INSERT INTO productj(product_id,product_name,product_price,product_image,admin_id,
product_descriptioon,cat_id,quantity,location_id) Values('$pid','$pname','$pprice','$img','$adminid','$pdescription',
'$catid','$pquantity','$loc')");
$q4= $conTL1->query("INSERT INTO product(product_id,product_name,product_price,product_image,admin_id,
product_description,cat_id,quantity,location_id) Values('$pid','$pname','$pprice','$img','$adminid','$pdescription',
'$catid','$pquantity','$loc')");
if($q3==false || $q4==false)
{
array_push($error,'Error in adding the product to jeddah databases');
}
if(!empty($error))
{
foreach ($error as $key => $value)
{
echo '<script> alert($value);</script>';
}
$conTL2->rollback();
$conTL1->rollback();
}
else
{
$conTL2->commit();
$conTL1->commit();
echo '<script> alert("The item has been added successfully to jeddah database!");</script>';
}
}//end if jeddah
?>
Upvotes: 1
Views: 93
Reputation: 1942
Use this line to display alert instead:
echo "<script> alert('$value');</script>";
If you need to put variable into your alert, double quotes "
have to be used outside and single ones '
inside.
UPDATE
or, like @symcbean has mentioned, if you want it to be completely perfect you can do something like:
echo "<script> alert('" . addslashes($value) . "');</script>";
Upvotes: 2