Jump to content

Update db table from HTML form


benjudy

Recommended Posts

PHP / mysql n00b here, would be very appreciative of any help!

I'm trying to update a simple MySQL table from an HTML form and I'm stuck.

My db table is named [tt]relo[/tt]. It has five columns: [tt]id, address, city, sqft, price[/tt]. The column named [tt]id[/tt] is set to [tt]auto_increment[/tt].

I can figure out that if I submit the following query, it will update the first row in the db:

[tt]$query="UPDATE relo SET address='someaddress', city='somecity', sqft='somesqft', price='someprice' WHERE id='1'";[/tt]

But this doesn't quite get me where I need to be. What I want to do is allow the user to update my HTML form and hit a "submit" button, and [i]presto[/i] the db table is updated. The trick is, there could be any number of rows. So we are dealing with not just one row of data for these columns, but multiple rows.

I think what I need help with is creating a dynamic UPDATE that will use the values that were posted by the HTML form submission.

I created a dynamic HTML table and form that properly pulls in the data from the db table and puts it in the form textfields. So the user can edit the data in the textfields. I just can't figure out how to make the form submission update the db.

Does anyone have any sample code or helpful ideas? Thanks!

Link to comment
Share on other sites

I just realized there's a simpler way for me to pose my question. I'd like to see if anyone can help me with this...

I have an array with the following keys and values:

submitid1 = 1
address1 = sample address1
city1 = sample city1
sqft1 = sample sq ft1
price1 = sample price1
submitid2 = 2
address2 = sample address2
city2 = sample address2
sqft2 = sample address2
price2 = sample address2

I have a MySQL db table named relo. It has five columns: id, address, city, sqft, price.

How do I write a SQL UPDATE statement (dynamically, using PHP) that will update my db table with the data in my array?
Link to comment
Share on other sites

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.