benjudy Posted December 6, 2006 Share Posted December 6, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/29596-update-db-table-from-html-form/ Share on other sites More sharing options...
benjudy Posted December 6, 2006 Author Share Posted December 6, 2006 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 = 1address1 = sample address1city1 = sample city1sqft1 = sample sq ft1price1 = sample price1submitid2 = 2address2 = sample address2city2 = sample address2sqft2 = sample address2price2 = sample address2I 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? Quote Link to comment https://forums.phpfreaks.com/topic/29596-update-db-table-from-html-form/#findComment-135830 Share on other sites More sharing options...
fenway Posted December 6, 2006 Share Posted December 6, 2006 Sound like you need to compose two separate update statements based on the counter. Quote Link to comment https://forums.phpfreaks.com/topic/29596-update-db-table-from-html-form/#findComment-135954 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.