help, i would like to put a conditional statement if the quantity that customer will buy exceeds the remaining quantity in the inventory,and it will prompt a message that the transaction is invalid, heres my code.in buying portal.advance thanks for the help :)

<?php
    require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
    color: #000000;
    font-weight: bold;
    font-size: 24px;
}
-->
</style>
</head>

<body>
<form action="saveorder.php" method="post">
<input name="id" type="hidden" value="<?php echo $_SESSION['SESS_MEMBER_ID']; ?>" />
<input name="transcode" type="hidden" value="<?php echo $_SESSION['SESS_FIRST_NAME']; ?>" />
<table width="400" border="0" cellpadding="0" cellspacing="0">
<?php

                  if (isset($_GET['id']))
            {


            include('config.php');

            $id=$_GET['id'];

            $result = mysql_query("SELECT * FROM marias_products WHERE product_id = $id and status='available'");

            $row3 = mysql_fetch_array($result);

  echo '<tr>';
    echo '<td width="80"><img alt="furniture" src="images/products/'.$row3['product_photo'].'" /></td>';
    echo '<td width="200"><span class="style1">'.'</span></td>';
    echo '<td width="120"></span></td>';
  echo '</tr>';
  echo '<tr>';
    echo '<td width="80"><input name="name" type="text" value="'.$row3['product_name'].'" readonly/><input name="ids" type="hidden" value="'.$row3['id'].'"/></td>';
    echo '<td width="120"></span></td>';
  echo '</tr>';
  }
            ?>

</table>
<br />
  <label style="color:#000000;">Qty:
  <input type="text" name="qty" />
  </label>
<br />
<table width="300" border="0" cellpadding="0" cellspacing="0" style="color:#000000;"> 
  <tr>

    <td width="100">Quality</td>
    <td width="100">Price</td>
    <td width="93">Selection</td>
  </tr>




  <?php

                  if (isset($_GET['id']))
            {


            include('config.php');


            $id=$_GET['id'];
            $result = mysql_query("SELECT * FROM marias_products WHERE product_id = $id");

            while($row3 = mysql_fetch_array($result))
            {
            $resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE '%".$id."%'");

            while($rows = mysql_fetch_array($resultq))
{ 
$qwerty=$rows['qtyleft'];
}       
if ($qwerty!=0){            


  echo '<tr>';

    echo '<td>'.$row3['product_quality'].'</td>';
    echo '<td>'.$row3['product_price'].'</td>';
    echo '<td>'.'<input name="but" type="image" value="'.$row3['id'].'" src="images/78.png" />'.'</td>';
  echo '</tr>';
  }
  else
  {
  echo 'not available';
  }

            }

            }
            ?>
</table>
</form>
</body>
</html>
Member Avatar for diafol

Am getting sidetracked by all the embedded html. Try to keep your html and php as separate as possible. Instead of eachoing everything out, you can place things into variables using concatentation and echo them out in relevant places.

All you need is retrieve the number-in-stock from the table and test that against the number from the form:

$num_in_stock = $rows['qty_left'];
$num_reqd = intval($_POST['qty'];
if($num_reqd > $num_in_stock){
    //error message
}else{
    //process
}

dunno how to separate lol, im so noob in php, :| btw where do i place that conditional? im having logical problem, thankyou very much for the help and reply mate. thanks a lot

Member Avatar for diafol

where do i place that conditional?

lol I have no idea! I can't see where your code gets the number that the user requires from the form (what form?). Or is this supposed to be 'one item only on button click'?

lol, btw. thanks for the help mate :)thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.