Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

how to do the calculation for current stock

$
0
0
hi, im new here.


I had a problem about to calculate the current stock. How I can deduct a value from database ? I had a form that contain a value that will be deduct from database.

value from database (inStock) - value from form(prod_taken)(php)=$result

the $result will update the inStock in database.

The conclusion is, how I create a code for calculation?
This is my code:


if(isset($_POST['submitted'])){

$rp=trim($_POST['NoRp']);
$p=trim($_POST['prod_id']);
$pn=trim($_POST['product']);
$pk=trim($_POST['prod_taken']);

$un=trim($_POST['unit']);
$t=trim($_POST['terminal']);



	
	
$errors=array(); 



if (empty($_POST['prod_id'])){
$errors[] ='Please enter the product id';
} else {
$p=trim($_POST['prod_id']);
}



if (empty($errors)) {

	

$sql= "INSERT INTO issue ( NoRp, prod_id, product, prod_taken, unit,terminal,date) VALUES
('$rp','$p','$pn','$pk','$un','$t', NOW() )";
$result=@mysql_query($sql); 
if($result) {


echo'<center><h1 id="mainhead">Thank you!<h1>
</center>';



echo "<center><a href=homeAdmin.php>BACK</a></center>";


exit();
} else {
echo '<h1 id="mainhead">System Error</h1>
<p class="error">  System error. We apologize for any inconvenience.</p>';




exit();
}

mysql_close();
}else {
echo '<h1 id="mainhead"> Error!</h1>
<p class="error"> The following error(s) occurred:<br/>';
foreach($errors as $msg) {
echo "- $msg<br/>\n";
}
echo '</p><p> Please try again.</p><p><br/></p>';
}
}

?>



Please fill the form below
<form action="stockform.php" method="post">

	<p>Rp No: <input type="text" name="NoRp" size="20" maxlength="40" value="<?php if (isset($_POST['NoRp']))  echo $_POST['NoRp']; ?>"/></p>
	<p>Product id: <input type="text" name="prod_id" size="20" maxlength="40" value="<?php if (isset($_POST['prod_id']))  echo $_POST['prod_id']; ?>" /></p>


	<p>
<?php
$user="root"; //user for server
$host="localhost"; //host for server
$username=""; //user for server
$password=""; //password for server
$database="inventory"; //database for server
$table="product"; //table for server

mysql_connect($host, $user, $password) or die ("can't connect");
mysql_select_db($database) or die (mysql_error());

$query = "SELECT prodName FROM product" ;
$result = mysql_query($query);
echo'Product Name: <select name="product">';
while($row = mysql_fetch_assoc( $result )) { 
        echo '<option value="'.$row['prodName'].'">' . $row['prodName'] . '</option>';   
}
echo '</select>';
?></p>

		 <p>Total Taken: <input type="text" name="prod_taken" size="20" maxlength="40" value="<?php if (isset($_POST['prod_taken']))  echo $_POST['prod_taken']; ?>"/></p>
		
        <p>
<?php
$user="root"; //user for server
$host="localhost"; //host for server
$username=""; //user for server
$password=""; //password for server
$database="inventory"; //database for server
$table="unit"; //table for server

mysql_connect($host, $user, $password) or die ("can't connect");
mysql_select_db($database) or die (mysql_error());

$query = "SELECT unitName FROM unit" ;
$result = mysql_query($query);
echo'Unit: <select name="unit">';
while($row = mysql_fetch_assoc( $result )) { 
        echo '<option value="'.$row['unitName'].'">' . $row['unitName'] . '</option>';   
}
echo '</select>';
?></p>

 <p>
<?php
$user="root"; //user for server
$host="localhost"; //host for server
$username=""; //user for server
$password=""; //password for server
$database="inventory"; //database for server
$table="terminal"; //table for server

mysql_connect($host, $user, $password) or die ("can't connect");
mysql_select_db($database) or die (mysql_error());

$query = "SELECT terName FROM terminal" ;
$result = mysql_query($query);
echo'Terminal: <select name="terminal">';
while($row = mysql_fetch_assoc( $result )) { 
        echo '<option value="'.$row['terName'].'">' . $row['terName'] . '</option>';   
}
echo '</select>';
?></p>

		



	
	
	<br>
	
	<p align="center"><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE"/>
</form>


			</table>
		</td>
      </tr>
    </table>
	</td>
  </tr>
</table>
	</td>
  </tr>
</table>

</body>
</html>


tq

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>