Jump to content

Editing MQSQL Database records using text boxes


penix
 Share

Recommended Posts

I've got a slight problem, i'm, faily new to MYSQL/PHP and i've run into a problem i'm having a hard time sorting out.So I need to make a admin panel of sorts, i've got a page displaying prices from a MYSQL databse, but I need to make it so the prices can be edited from this admin panel.I need the prices and dates to be displayed in text boxes like this:Dates: [text box displaying date] Prices: [text box displaying price] Dates: [text box displaying another date] Prices: [text box displaying another price] Dates: [text box displaying another date] Prices: [text box displaying another price] ect (there are 9 sets of prices and dates)[submit button]Then the user can edit a price or date in the text box click the update button and it will update the actual prices page.I'd apprechate any help what-so-ever as im totally stuck, many thanks for readingRegards Josh.

Link to comment
Share on other sites

A couple questions, do you know how to make html forms? Do you have a form already inserting this data into the database?With textboxes, you can prepopulate them by putting some php in their value property. Like this:<label>Event: <input type="text" name="price" value="<?php echo $price; ?>"></input></label>Now to do this, you have to know how to perform a query in php, do you know how to do that?

Link to comment
Share on other sites

Thankyou for the reply :)I've put the data straight into the MYSQL database becuase those are the prices at the moment, but in the future the user will need to update the prices.I came up with this earlier, it seems to display the text boxes and enter the correct data into them (i'm not sure if this code is actually right though, as this is my first time with mysqp/php)

<?php do { ?><form action="insert.php" method="post">Date: <input value="<?php echo $row_Prices['Date']; ?>" type="text" name="Date" />Price: <input value="<?php echo $row_Prices['Price']; ?>" type="text" name="Price" /><br /><?php } while ($row_Prices = mysql_fetch_assoc($Prices)); ?><br /><input type="submit" /></form>

but then it ends there as i dont know how to, once updated with new prices, update the actual mysql database.And no, I dont know how to preform a query (well i dont think i do)Thankyou ever so much for the helpJosh.

Link to comment
Share on other sites

You want to use a normal while loop there instead of a do..while loop. If you use a do loop you'll need to do a priming read first (set the $row_Prices variable) and make sure it's valid before going through the loop the first time. The syntax for while is similar to do. Also, you shouldn't have the form tag in the loop, that should only get printed once.

<form action="insert.php" method="post"><?php while ($row_Prices = mysql_fetch_assoc($Prices)) { ?>Date: <input value="<?php echo $row_Prices['Date']; ?>" type="text" name="Date" />Price: <input value="<?php echo $row_Prices['Price']; ?>" type="text" name="Price" /><br /><?php } ?><br /><input type="submit" /></form>

Check the w3schools site for the PHP forms tutorial, or check the PHP tips thread in this forum to see how to get the information from the form. Also, you shouldn't have more then one form element with the same name. If you know how many there are going to be you can number everything, like Date1, Price1, Date2, Price2, etc. Or, you can make each of them an array and store all the values in the array and then loop through the array to read everything. To make them an array put brackets after the name.Date: <input value="<?php echo $row_Prices['Date']; ?>" type="text" name="Date[]" />Price: <input value="<?php echo $row_Prices['Price']; ?>" type="text" name="Price[]" />

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...