Unanswered: database update question: capturing data from a form
My apologies since this is not a strictly mysql question . . . more php.
I'm trying to update a database by building a form that links a city with surrounding towns. I want to enter the main town and the surrounding towns and then it updates all records that contain the main town. the code runs without errors, but the data i'm entering is not finding its way into the variables and doesn't update the database . . . all help appreciated.
Is the whole script called demograph_updatep2.php, or is it split up into different script names?
Can you echo out the $_GET/$_POST variables and post what you're getting
e.g. insert the following into your code somewhere...
its split into the first page demo_update.php, which contains the code you saw. and a second page, which just displays results. i went ahead and inserted your code at the end of the page along with
When you submit the form you're going to demograph_updatep2.php
So basically anything at the bottom of demo_update.php is not getting executed properly. Your update SQL and PHP code needs to be put into the demograph_updatep2.php becuase that's where all your data you put into the boxes is being sent...
I think you need to echo mysql_error();
Nevertheless, the SQL is not necessarily failing. Think it through, you are updating some columns where one of those columns equals a particular value,
e.g. update <tablename> SET column2='somenewvalue',column3='somenewvalue' WHERE column1 IN ('somevalue')
(as a side note there is nothing wrong with using IN but I would use = , because what is inside the bracket is constant)
So what does this do? Well, it updates column2 & 3 where column1 = 'somevalue'.
Ok, i'm MySQL, i'm searching through all the rows in my table, and I find three rows that have column1='somevalue'. Ok great, i'll update column2 and 3 for those rows then. Done.
I'm searching through all the rows in my table, and i find zero (0) rows that have column1='somevalue'. What do I have to update? Nothing...! So I don't update anything. Done.
Can you see something here?
There is no error. MySQL has searched through our results and hasn't found any to update so it doesn't update any. That's a perfectly valid result.
Your problem is not that your SQL is wrong, it's that you don't have anything in the table to update...