![]() |
Insert into Dynamic DB
Hi all. Have been trying to get my head around this simple problem.
My webpage displays from my database a table of 1) ID's, 2) a checkbox which toggles the visibility of 3) a textbox So my output looks like this: 1 [✔] _________ 2 [] 3 [✔] _________ 5 [] 8 [] The form has a submit button which on click I want to update a column called 'complete' with the text from the textbox. So far my code is: PHP Code:
This works fine and produces the result I need. When I want to post this information the code I have so far is: PHP Code:
|
First of all, you didn't say what the problem you're having actually is. "It doesn't work" isn't very helpful; you really should be catching query errors so you know exactly what's going on with your queries.
PHP Code:
PHP Code:
Second, the name "eid[event_id]" is not going to change on each iteration in your loop, so you're going to end up with only one entry in your $_POST array. To see how PHP is interpreting your form elements over to the $_POST array, use this: PHP Code:
|
Thanks for the reply Fumigator, by 'not working' I should have explained that the UPDATE event query updates the complete field with a blank value.
Removing the [event_id] and setting the complete field to equal $eid returns correctly the $eid value of the highest id. In my case 4. So the last row of the db is updated with the complete value as 4 (which is correct as the ID of this row is 4) From this I presume I need a way to make each textbox a unique ID that I can then refer to when I post? |
This is my idea ... everyone else beat me to the post.
Examine all of the ideas and put together a plan. You'll want to use an array for both the checkboxes and textboxes. The value of the checkbox will be an index number ... With PHP, when you process the checkbox array, the array will only contain the boxes that were checked. So in your example where you are showing box 1 and 3 checked ... the checkbox array will only have two items in it. You won't know which ones were checked, so you need to example the values of them ... and then you know. Here's an example: PHP Code:
Now, when you process the form .... use this to test it out ... PHP Code:
Untested ... but you can sort of get the idea. . |
Quote:
[eid] => Array ( [event_id] => 4 ) [eidtext] => Array ( [1] => [2] => [3] => three [4] => ) |
Quote:
Great work! Post to the correct ID in the database now. Only thing is that it updates complete as 'Array'. Do I need to change the column type in mysql? |
complete='$eidtext'
should be: complete='$eidtext[$item]' . |
| All times are GMT +1. The time now is 06:44 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.