February 16th, 2013, 03:33 PM
Your html is incorrect also. attribute values should be in quotes.
Originally Posted by jlewis01
echo "<input type=\"checkbox\" name=\"pulledQty\" value=\"$inverseQty\">";
February 18th, 2013, 08:22 AM
Yes, thank you. I am aware of proper html but I dont think this resolves my issue as proposed here.
Originally Posted by BarryG
February 18th, 2013, 09:32 AM
Okay, I think I have it figured out. It does work as expected. Please take a look and see if you agree that the code/logic is cleaner.
foreach(array_keys($_POST['pulledQty']) as $index)
echo $submitQuery = $_POST['pulledQty'][$index].",".$_POST['pulledItem'][$index];
$result=mysql_query("INSERT INTO unionInv (unionInvItem,unionQty) VALUES (".mysql_escape_string($_POST['pulledItem'][$index]).",".mysql_escape_string($_POST['pulledQty'][$index]).")")or die("Insert Error: ".mysql_error());
February 18th, 2013, 09:48 AM
Here's something to make it simple. Somewhat which requinix pointed out as his unfavored way. This will, however, build a little different. It would just be your item names, follow by an input box for quantity. Build your form like so:
Hidden field named "item['id']" value "idval"
Printed Liquor Name - Qty Input Box named "item['id']"
Replace 'idval' with however you reference your items, such as an id number, or item name. A far as the 'id' goes, just make the hidden match the following input. I suggest use numbers 0-...
Then, after submission, run a foreach() and if the Qty is greater than zero, run the INSERT query with provided values.
item[id] holds your item's ID number, or item name
item[id] holds the Qty value
EDIT: Or run an INSERT every foreach(). I wasn't sure if you wanted unchecked values entered as well or not. Just decide this via the if/else that would be within your foreach()
Last edited by Triple_Nothing; February 18th, 2013 at 10:06 AM.
February 18th, 2013, 10:29 AM
Otherwise, if you haven't exactly gotten it yet, perhaps a bit more of a story of the goal of the site, and how you wish it to work? The post of your that includes the code that builds your form kinda leaves me a little confussed on its desired use/function. Let me see if I got this right. And, if this isn't an order form, but perhaps inventory, are INSERTs your best intent?
ItemID //Displays item name
id //Item's ID number?
exchOrder //Current inv qty?
Checkbox input //Predefined order amount?
disQty //Random inv to add to this item?
If, and I'm kinda guessing, this is to be kinda both an inventory item, with an order option, I would run a UPDATE on current items to keep an INV table updated, and have another INV table hold your nightly/weekly INV checks, each night/week check to 1 row. Then make your checkbox trigger an if/then to proccess the order, if needed.
February 18th, 2013, 10:46 AM
You are correct and this is exactly what I have done. Your speculation about the use of the form is pretty much correct also. I do have one table update inventory and another is Inserted for a possible review if needed later.
Originally Posted by Triple_Nothing
Everything seems to be working as expected now. I am just wanting conformation the updated code for inserting the records is good.
February 19th, 2013, 07:42 AM
calling mysql_real_escape_string is useless when you don't wrap the value in quotes. This function only prevents the user from "breaking out" of a quoted string, it does not magically make the input secure or something.
And since you added the die(mysql_error()) back in and still have the mysql_close(), I'm not exactly sure if you're serious about the good code ...
February 19th, 2013, 07:49 AM
Serious and ignorance are not the same. Thank you for helping me to understand what I do not.
Originally Posted by Jacques1