1

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
?>

1 Answer 1

2

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>";
Sign up to request clarification or add additional context in comments.

5 Comments

I think Naija refers to the else part of the alert...done
@WilliamMadede you are right actually, but the first alert was still wrong. There is no more javascript problems except that line. But thanks
ofcourse, im not taking anything away from you...thats actually a good point...done
erm, should be print "<script> alert('" . addslashes($value) . "');</script>";
Thank you so much pavlovich <3 I am going to try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.