Jump to content
Sign in to follow this  
sompal

PHP

Recommended Posts

<?php 
$dbConn = new mysqli("localhost", "student", "Autumn", "fact");
if($dbConn->connect_error) {
die("Failed to connect to database " . $dbConn->connect_error);
}
?>

<?php  

error_reporting(E_PARSE);

//require_once("conn.php");

$number = $_POST["quantity"];

 if (isset($_POST["submit"])) { 
  
  if(!empty($number)){
  
if (is_numeric($number)){
     
     if($number < 60){
       
      $sql = "SELECT name, quantityInStock, price FROM product where quantityInStock > $number order by quantityInStock ASC ";
               $results = $dbConn->query($sql)
               or die ('Problem with query: ' . $dbConn->error); 
            
                  }
      
          else {      echo "<p class='errorMsg'>There are no products that have more than 60 in stock.</p>";
      
           }  
            }                                     
  
  
   else {
          echo "<p class='errorMsg'> The value entered for quantity was not a number. </p> ";
           }
           }
           else
           
           {
           echo "<p class='errorMsg'>input can not be blank</p> ";
           }
   }        
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <style>
      input[type="text"] {border: 1px solid black;}
    </style>
    <link rel="stylesheet" href="styles.css">
    <title>Quiz</title>
  </head>
  <body> 
      <form id="" action="" method="post"> 
<h1>Product In Stock </h1>
<table>
<tr>
<th>Name</th>
<th>QuantityInStock</th>
<th>Price</th>
</tr>
<?php
while ($row = $results->fetch_assoc()) { ?>
<tr>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["quantityInStock"]?></td>
<td><?php echo $row["price"]?></td>
</tr>

<?php }  

$dbConn->close(); ?>
</table>
    
    
    
    </form>
  </body>
</html>

Share this post


Link to post
Share on other sites

Is there a question here?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...