Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to update a qunatity if itemname is same in mysql using php
    primarykey
    data
    text
    <p>when i got a item from company then i enter a all item detail in my PHP form and its save in MySQL</p> <p>and there are two table in MySQL one is receive and 2nd is stock</p> <p>so when i got a item its save in two table receive and stock</p> <p><strong>but some time stock (table) item is same so i want to update if item name and company is same then it will change quantity only</strong></p> <p><strong>and some time its new item then it will save normally</strong></p> <p>so how can i do this please help me to fix this issue thanks</p> <pre><code> mysql_query("INSERT INTO receive SET date='$date',company='$company',itemname='$itemname',quantity='$quantity',category='$category',signature='$signature'"); $result = mysql_query("INSERT INTO stock SET date='$date',company='$company',itemname='$itemname',quantity='$quantity',category='$category',signature='$signature'") </code></pre> <p>this is my complete script <pre><code> // 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($id ,$date ,$company,$itemname,$quantity,$category,$signature, $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 Receive!&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" &gt;Company :&lt;/label&gt; &lt;input name="company" type="text" id="company" value="&lt;?php echo $company; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" for="item"&gt;Item: &lt;/label&gt; &lt;input name="itemname" type="text" id="itemname" value="&lt;?php echo $itemname; ?&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" id="quantity" value="&lt;?php echo $quantity; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" &gt;Category :&lt;/label&gt; &lt;input name="category" type="text" id="category" value="&lt;?php echo $category; ?&gt;" size="30"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label class="field" for="username"&gt;Signature : &lt;/label&gt; &lt;input name="signature" type="text" id="signature" readonly value="&lt;?php echo $_SESSION['SESS_FIRST_NAME']; ?&gt;"&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 } $itemname = $_GET['itemname']; // 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 $id = mysql_real_escape_string(htmlspecialchars($_POST['id'])); $date = mysql_real_escape_string(htmlspecialchars($_POST['date'])); $company = mysql_real_escape_string(htmlspecialchars($_POST['company'])); $itemname = mysql_real_escape_string(htmlspecialchars($_POST['itemname'])); $quantity = mysql_real_escape_string(htmlspecialchars($_POST['quantity'])); $category = mysql_real_escape_string(htmlspecialchars($_POST['category'])); $signature = mysql_real_escape_string(htmlspecialchars($_POST['signature'])); // 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($id ,$date ,$company,$itemname,$quantity,$category,$signature, $error); } else { // save the data to the database mysql_query("INSERT INTO receive SET date='$date',company='$company',itemname='$itemname',quantity='$quantity',category='$category',signature='$signature'"); $result = mysql_query("INSERT INTO stock SET date='$date',company='$company',itemname='$itemname',quantity='$quantity',category='$category',signature='$signature'") or die(mysql_error()); echo "&lt;center&gt;Recive 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.
    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.
    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