简体   繁体   中英

Displaying a number from the database in a javascript alert box

The following code is to used to display an alert box with the order number when a html form is submitted successfully!

$mysql="SELECT MAX(OrderNo.) FROM `order`  ";
 $results=mysqli_query($db,$mysql);

     $row=mysqli_fetch_array($results);

       echo '<script type="text/javascript">';



   echo 'alert("Successful signup your order number is"';
       echo $row['OrderNo.'];
    echo ")";
    echo '</script>';

Though the alert box appears with "Successful signup your order number is" part, the OrderNo. part(retrieved from a databse table) does not appear in the alert box! Here max is used because the latest orderNo. is to be displayed and the OrderNo. field is auto incremented. please help me to correct this error

You are not closing double quotes correctly.

It should be:

echo 'alert("Successful signup your order number is ';
echo $row['OrderNo.'];
echo '")';

Or better:

echo 'alert("Successful signup your order number is '.$row['OrderNo.'].'")';

Try to create an alias for the grouped number like this:

SELECT MAX(OrderNo) AS number FROM order

And show with:

echo 'alert("Successful signup your order number is' . $row['number'] . '")';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM