Stalingrad Posted March 11, 2013 Share Posted March 11, 2013 Hi there! I've been having some trouble for quite some time now with a form. I have a table that I'm grabbing data from. I want to update multiple rows with a form. However, I have multiple text boxes under each row I want to update with only one submit button. When I press the submit button nothing happens. I'm not sure why. I've been having trouble with this forever, like I said. I would really, really like to get this done as it's holding me back from doing other things on my site. I will post the part of the code where I'm having the trouble. I don't think I will need to post the whole code since there are other parts of it that don't involve this at all. Here is the code: if($action == "stock") { $setprice = $_POST['price']; $updateprice = $_POST['updateprice']; echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Stock Shop</font><br><br>"; $eq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY theitemid"; $ee = mysql_query($eq); while($erow = mysql_fetch_array($ee)) { $eeloc = $erow['location']; $eeid = $erow['theitemid']; $eenowid = $erow['uitemid']; $eeprice = $erow['price']; $wq = "SELECT * FROM items WHERE itemid='$eeid'"; $ww = mysql_query($wq); while($wrow = mysql_fetch_array($ww)) { $cq = mysql_query("SELECT * FROM uitems WHERE username='$showusername' AND location='2' AND theitemid='$eeid'"); $lcq = mysql_num_rows($cq); $fid = $wrow['itemid']; $fname = $wrow['name']; $fimage = $wrow['image']; $frarity = $wrow['rarity']; $fdesc = $wrow['description']; echo "<br>$fname<br><img src=/images/items/$fimage><br><br>"; ?> <input type="text" name="price" value="<?php echo "$eeprice"; ?>"><br></form> <?php } ?> <?php } ?> <br><br><input type="submit" name="updateprice" value="Update Prices"><br><br> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"></form> <?php if(isset($setprice)) { mysql_query("UPDATE uitems SET price='$setprice' WHERE username='$showusername' AND theitemid='$fid'"); echo "<font color=green>Success! Your prices have been set and updated!</font><br><br>"; } } Before anybody says anything about it, I know my variable names are ridiculous.. so you don't even need to say that, lol. I have trouble naming my variable because I use so many in my codes. I'll have to come up with a better way to name them. Basically what this code is doing is grabbing the data with the specific location, displaying it and displaying the form. However, the form is not updating. Any help would be appreciative! Also, there was a time when the form DID work, but it did not update.... it just reloaded the page and left the text fields blank. Thanks again guys! Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/ Share on other sites More sharing options...
akphidelt2007 Posted March 11, 2013 Share Posted March 11, 2013 First thing you need to do is wrap your inputs within the form tag. Next if you want to deal with multiple form inputs with the same name you have to create an array. So basically <input type="text" name="price[]" value="<?php echo "$eeprice"; ?>"> Than once you mess with that if you have any more questions, come back here. Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418042 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 I'm not understanding... I replaced the code with what you wrote, and it still is not updating... is there something I am missing here? Thank you for replying by the way. Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418054 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 Okay I got it to work, but now it updates.. not what I want it to, but they are all blank except for the last one.. it says "Array"... Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418061 Share on other sites More sharing options...
akphidelt2007 Posted March 11, 2013 Share Posted March 11, 2013 You want to update prices for multiple items, correct? $_POST['price'] is now an Array of prices... as in $_POST['price'] = Array('price1','price2') So in order to update multiple line items you will have to verify the form has been submitted than loop through the line items again to update the prices. Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418063 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 Yes, multiple items (rows) they are in the same table. Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418065 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 I don't understand what you mean by array... and setting it... the user sets their own price, I can't set the array price... Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418066 Share on other sites More sharing options...
akphidelt2007 Posted March 11, 2013 Share Posted March 11, 2013 I don't understand what you mean by array... and setting it... the user sets their own price, I can't set the array price... Ok, let me get this straight. You have a table of items. Next to each item is a price that a user can set, correct? And a user can update the price of multiple items and click "Update Price" and you want it to go through and update the prices for each item? Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418070 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 Yes Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418073 Share on other sites More sharing options...
Stalingrad Posted March 11, 2013 Author Share Posted March 11, 2013 And I did what you told me to, and now it brings to back to the page,and each item has a blank box, but the last item has 'Array" written in it... Quote Link to comment https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/#findComment-1418074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.