Jump to content

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/275523-dynamic-update-form-in-php/
Share on other sites

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.

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.