473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to update mysql with varying quantities of information?

I have several files that function as an update service for a mysql database.
The first file, updatebyitem.php functions as a database search for a specific item. Next, updatebyitemprocess.php finds the results of the search and outputs them in a table with checkboxes. I made it so that you can select checkboxes and push the "Edit" button, which will take you to editselection.php that outputs the rows that were checked for editing in text areas. The next step for me is to take all of the new, edited information and update the mysql database. I have no idea how to do this next part because the amount of information that is being updated varies by the amount of checkboxes selected for editing in updatebyitemprocess.php.
Any help appreciated.

-Brandon
(Mysql and php programmer for 2 days)



*** FILE *** "updatebyitem.php"

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Update By Item</title>
  3. <?php 
  4.     include("menu.php");
  5.     include("sqlconnect.php");
  6. ?>
  7. <body>
  8. <p align="center">
  9.     Search Inventory by <b>ITEM</b> for update:
  10.     <form align="center" name="updatebyitem" id="updatebyitem" action="updatebyitemprocess.php" method="post">
  11.     <input name="item" type="text">
  12.     <input type="submit" value="Search">
  13.     <br /><br />
  14.     <INPUT TYPE="BUTTON" VALUE="<-- Back to Menu" ONCLICK="window.location.href='http://localhost/Inventory/updatemenu.php'">
  15.     </form>
  16. </p>
  17. </body>
  18. </html>
*** FILE *** "updatebyitemprocess.php"

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Search By Item Results</title>
  3. <?php 
  4.     include("menu.php");
  5.     include("sqlconnect.php");
  6. ?>
  7. <body>
  8.         <p align='center'><INPUT TYPE="BUTTON" VALUE="<-- Back to Search" ONCLICK="window.location.href='http://localhost/Inventory/updatebyitem.php'">
  9.  
  10.         <form name="updateselect" action="editselection.php" method="post">
  11.  
  12. <?php
  13.         $item = $_POST['item'];
  14.         echo "The item you entered was: <b>" . $item . "</b>";
  15.  
  16.         echo "<table border='1' class='dataTable' cellspacing='0'>
  17.                         <thead>
  18.                         <tr><th>Selection</th>
  19.                         <th>Brand</th>
  20.                         <th>Supplier</th>
  21.                         <th>Item Number</th>
  22.                         <th>Item Description</th>
  23.                         <th>Secondary Description</th>
  24.                         <th>Size & Volume</th>
  25.                         <th>Color</th>
  26.                         <th>Whole Cost</th>
  27.                         <th>Retail Cost</th>
  28.                         <th>Ideal Quantity</th>
  29.                         <th>Present Quantity</th>
  30.                         <th>Retail In Inventory</th>
  31.                         <th>Quantity To Order</th>
  32.                         <th>Item</th></tr>
  33.                         </thead><tbody>";
  34.  
  35.         $result = mysql_query("SELECT * FROM inventory WHERE Item LIKE '%$item'");
  36.         while ($row = mysql_fetch_array($result))
  37.             {
  38.             $row_id = $row['id'];
  39.             echo "<tr><td><input name='itemselect[]' type='checkbox' value='" . $row_id . "'></td>";
  40.             echo "<td>";
  41.             echo $row['Brand'];
  42.             echo "</td>";
  43.  
  44.             echo "<td>";
  45.             echo $row['Supplier'];
  46.             echo "</td>";
  47.  
  48.             echo "<td>";
  49.             echo $row['ItemNumber'];
  50.             echo "</td>";
  51.  
  52.             echo "<td>";
  53.             echo $row['ItemDescription'];
  54.             echo "</td>";
  55.  
  56.             echo "<td>";
  57.             echo $row['TypeSizeVolume'];
  58.             echo "</td>";
  59.  
  60.             echo "<td>";
  61.             echo $row['SizeVolume'];
  62.             echo "</td>";
  63.  
  64.             echo "<td>";
  65.             echo $row['Color'];
  66.             echo "</td>";
  67.  
  68.             echo "<td>";
  69.             echo $row['WholeSaleCost'];
  70.             echo "</td>";
  71.  
  72.             echo "<td>";
  73.             echo $row['RetailCost'];
  74.             echo "</td>";
  75.  
  76.             echo "<td>";
  77.             echo $row['IdealQuantity'];
  78.             echo "</td>";
  79.  
  80.             echo "<td>";
  81.             echo $row['QuaninInventory'];
  82.             echo "</td>";
  83.  
  84.             echo "<td>";
  85.             echo $row['RetailDollarsInInventory'];
  86.             echo "</td>";
  87.  
  88.             echo "<td>";
  89.             echo $row['QuantityToOrder'];
  90.             echo "</td>";
  91.  
  92.             echo "<td>";
  93.             echo $row['Item'];
  94.             echo "</td>";
  95.  
  96.             echo "</tr>";
  97.  
  98.         }
  99.  
  100.  
  101. ?>
  102. </tbody>
  103. </table>
  104. <br /><br />
  105. <input type="submit" value="Edit">    
  106. </form>
  107. </p>
  108. </body>
  109. </html>
  110.  
*** FILE *** "editselection.php"

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Edit Selection</title>
  3. <body>
  4. <?php
  5.     include("menu.php");
  6.     include("sqlconnect.php");
  7.  
  8.  
  9. ?>
  10.  
  11. <p align="center"><b>Make your updates --</b></p>
  12. <style>
  13. textarea {resize: none;}
  14. </style>
  15. <form name="edits" action="updatecomplete.php" method="post">
  16. <?php
  17.  
  18.         //$row_id = $_POST['itemselect'];
  19.         $row_id = array();
  20.         foreach ($_POST['itemselect'] as $entry)
  21. {
  22.  
  23.                 $row_id[] = $entry;
  24.  
  25.  
  26.         $result = mysql_query("SELECT * FROM inventory WHERE id='" . $entry . "'");
  27.         while ($row = mysql_fetch_array($result))
  28.         {
  29.             echo "Item Selected: <b>" . $row['Item'] . "</b><br/><br />";
  30.             echo "<b>Brand: <b><br /><textarea name='brandedit'>" . $row['Brand'] . "</textarea><br /><br />";
  31.             echo "<b>Supplier: </b><br /><textarea name='supplieredit'>" . $row['Supplier'] . "</textarea><br /><br />";
  32.             echo "<b>Item Number: </b><br /><textarea name='itemnumberedit'>" . $row['ItemNumber'] . "</textarea><br /><br />";
  33.             echo "<b>Item Description: </b><br /><textarea name='itemdescriptionedit'>" . $row['ItemDescription'] . "</textarea><br /><br />";
  34.             echo "<b>Secondary Description: </b><br /><textarea name='secondarydescriptionedit'>" . $row['TypeSizeVolume'] . "</textarea><br /><br />";
  35.             echo "<b>Size & Volume: </b><br /><textarea name='sizevolumeedit'>" . $row['SizeVolume'] . "</textarea><br /><br />";
  36.             echo "<b>Color: </b><br /><textarea name='coloredit'>" . $row['Color'] . "</textarea><br /><br />";
  37.             echo "<b>Wholesale Cost: </b><br /><textarea name='wholecostedit'>" . $row['WholeSaleCost'] . "</textarea><br /><br />";
  38.             echo "<b>Retail Cost: </b><br /><textarea name='retailcostedit'>" . $row['RetailCost'] . "</textarea><br /><br />";
  39.             echo "<b>Ideal Quantity: </b><br /><textarea name='idealquantityedit'>" . $row['IdealQuantity'] . "</textarea><br /><br />";
  40.             echo "<b>Present Quantity: </b><br /><textarea name='presentquantityedit'>" . $row['QuaninInventory'] . "</textarea><br /><br />";
  41.             echo "<b>Retail $ In Inventory: </b><br /><textarea readonly='readonly' name='retailininventoryedit'>" . $row['RetailInInventory'] . "</textarea><br /><br />";
  42.             echo "<b>Quantity to Order: </b><br /><textarea readonly='readonly' name='quantitytoorderedit'>" . $row['QuantityToOrder'] . "</textarea><br /><br />";
  43.             echo "<b>Item: </b><br /><textarea name='itemedit'>" . $row['Item'] . "</textarea><br /><br /><br />";
  44.             echo "<hr size='10' align='center' color='#FF0000'>";
  45.         }    
  46.  
  47. }
  48. ?>
  49. <br />
  50. <input type="submit" value="Submit Updates">
  51. </form>    
  52. </body>        
  53. </html>
Jun 21 '12 #1
1 2182
Luuk
1,047 Expert 1GB
With the code above your selection does not make it to 'editselection.php'

You should give each checkbox in 'updatebyitemprocess.php' a unique name, like 'itemselect1', 'itemselect2', ...etc

In 'editselection.php' add an
Expand|Select|Wrap|Line Numbers
  1. var_dump($_POST);
to test what values get POSTed... (link)
Jun 22 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
1
by: The Bear | last post by:
does anyone know how to update a mysql database using C# or any other language for that matter. I keep getting the following error when I try to update: " Dynamic SQL generation is not supported...
4
by: whitemoss | last post by:
Hi, I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors: client.c: In function senddata:...
4
by: geof | last post by:
Hi ! this is my first post where is my error code in line 15 ($sql ) <html> <head><title> update MySQL Data </title></head> <body bgcolor="#FFFFFF"> <?
1
by: roger.rigsby | last post by:
Ok I know how to get the data I want from mysql but I need to actually do something with this data and then send it back to mySQL. Company heads love the spreadsheet view so this is serious...
1
tolkienarda
by: tolkienarda | last post by:
i need to update a database table using variables in unusual places here are the update statements mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");...
1
by: Viperoptic | last post by:
Hi All I am doing an update query from MS Access on a few records. The update work once perfectly but a soon as I run it again it returns the error below... "I have 5 records that won't do...
11
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP...
3
by: olddocks | last post by:
i have a strange problem. I have a massive database with primary key being autoincrement ID and other fields. The company i work with often publishes the data in excel sheet and i converted to mysql...
1
by: blekok | last post by:
I'm trying to use MS Access for the front end and MySQL as the Data source. I have this MS Access form which uses a table called hotel:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.