Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update stock quantity using MySQL in PHP
    primarykey
    data
    text
    <p>All stock saved already in stock table. But how can I update stock quantity when I sell my product? I want to update my stock table quantity row. I'm using MySQL.</p> <p>table name <code>stock</code>:</p> <pre><code>-------------------------------------------------------------------- id|username | date | item | quantity| amount ------------------------------------------------------------------ 1 |xyz |2013-10-09 | computer |25 | 25.00 ----------------------------------------------------------------- </code></pre> <p>and this is <code>sale</code> table:</p> <pre><code>-------------------------------------------------------------------- id|username | date | item | quantity| amount ------------------------------------------------------------------ 1 |xyz |2013-10-09 | computer |25 | 25.00 ----------------------------------------------------------------- </code></pre> <p>and this is sale.php page. When I sell a product this page save a record in sale table but i want to update stock table quantity row:</p> <pre><code> &lt;?php /* NEW.PHP Allows user to create a new entry in the database */ // creates the new record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($date ,$username,$item,$quantity,$amount, $error) { ?&gt; &lt;form id="searchform" action="" method="post" enctype="multipart/form-data"&gt; &lt;div align="center"&gt; &lt;fieldset&gt; &lt;div align="center"&gt; &lt;legend align="center" &gt;Stock!&lt;/legend&gt; &lt;/div&gt; &lt;div class="fieldset"&gt; &lt;p&gt; &lt;label class="field" for="date"&gt;Date: &lt;/label&gt; &lt;input name="date" type="text" class="tcal" value="&lt;?php echo date("Y-m-d");; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" for="username"&gt;User Name : &lt;/label&gt; &lt;input name="username" type="text" id="username" value="&lt;?php echo $username; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" for="item"&gt;Item: &lt;/label&gt; &lt;input name="item" type="text" value="&lt;?php echo $item; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" &gt;Quantity :&lt;/label&gt; &lt;input name="quantity" type="text" value="&lt;?php echo $quantity; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" &gt;Amount :&lt;/label&gt; &lt;input name="amount" type="text" value="&lt;?php echo $amount; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;p align="center" class="required style3"&gt;Please Fill The Complete Form &lt;/p&gt; &lt;div align="center"&gt; &lt;input name="submit" type="submit" class="style1" value="Submit"&gt; &lt;/div&gt; &lt;/form&gt; &lt;?php // if there are any errors, display them if ($error != '') { echo '&lt;div style="padding:4px; border:1px solid red; color:red;"&gt;'.$error.'&lt;/div&gt;'; } ?&gt; &lt;?php } // connect to the database include('connect-db.php'); // check if the form has been submitted. If it has, start to process the form and save it to the database if (isset($_POST['submit'])) { // get form data, making sure it is valid $date = mysql_real_escape_string(htmlspecialchars($_POST['date'])); $username = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $item = mysql_real_escape_string(htmlspecialchars($_POST['item'])); $quantity = mysql_real_escape_string(htmlspecialchars($_POST['quantity'])); $amount = mysql_real_escape_string(htmlspecialchars($_POST['amount'])); // check to make sure both fields are entered if ($date == '' || $quantity == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; // if either field is blank, display the form again renderForm($date ,$username,$item,$quantity,$amount, $error); } else { // save the data to the database mysql_query("INSERT sale SET date='$date', username='$username',item='$item',quantity='$quantity',amount='$amount'") or die(mysql_error()); echo "&lt;center&gt;Stock Enter Complete!&lt;/center&gt;"; // once saved, redirect back to the view page } } else // if the form hasn't been submitted, display the form { renderForm('','','','','','','','',''); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload