mysql - Generating error message for empty database query in PHP -


the following code's purpose input (from separate html file) customerid in database user , display order number, order date , shipped status customerid. code works fine , able this, want create error message if customerid not exist in database entered, instead of empty table. new php , on how appreciated. (please note, has in either php or mysql)

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>prac 2 task 8</title> </head> <body> <?php $conn = mysql_connect("localhost", "<username>", "<password>"); mysql_select_db("warehouse<##>", $conn)  or die ('database not found ' . mysql_error() ); $input = $_get["custid"]; $sql = "select ordernumber, orderdate, shipped orders customerid = $input  order orderdate";  $rs = mysql_query($sql, $conn) or die ('problem query' . mysql_error()); ?> <?php  if (ordernumber != "") { ?>  <p>the following information received user:</p> <p><strong>customerid = </strong> <?php echo "$input"; ?><br/><br/>  <table border="1" summary="order details"> <tr> <th>order number</th> <th>order date</th> <th>shipped</th> </tr> <?php while ($row = mysql_fetch_array($rs)) { ?> <tr> <td><?php echo $row["ordernumber"]?></td> <td><?php echo $row["orderdate"]?></td> <td><?php echo $row["shipped"]?></td>  </tr> <?php }} else { $txt ="the customerid entered either invalid or not exist";  echo $txt;?> <?php } mysql_close($conn); ?> </table> </body></html> 

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>prac 2 task 8</title> </head> <body> <?php $conn = mysql_connect("localhost", "<username>", "<password>"); mysql_select_db("warehouse<##>", $conn)  or die ('database not found ' . mysql_error() ); $input = $_get["custid"]; $sql = "select ordernumber, orderdate, shipped orders customerid = $input  order orderdate";  $rs = mysql_query($sql, $conn) or die ('problem query' . mysql_error()); //validate result set here if(mysql_num_rows($rs)>0) { ?> <?php  if (ordernumber != "") { ?>  <p>the following information received user:</p> <p><strong>customerid = </strong> <?php echo "$input"; ?><br/><br/>  <table border="1" summary="order details"> <tr> <th>order number</th> <th>order date</th> <th>shipped</th> </tr> <?php while ($row = mysql_fetch_array($rs)) { ?> <tr> <td><?php echo $row["ordernumber"]?></td> <td><?php echo $row["orderdate"]?></td> <td><?php echo $row["shipped"]?></td>  </tr> <?php }} else { $txt ="the customerid entered either invalid or not exist";  echo $txt;?> <?php }  }//endif else{  //you error message here }  mysql_close($conn); ?> </table> </body></html> 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -