Sorry for my English !
I have a poll system with one question and 4 answers :
Answer_id Question_id answers vote
10 1 ball 1
11 1 radio 3
12 1 tv 5
13 1 car 8
I have 4 input text to input the answers for users using the poll to vote:
<input type="text" name="ans1" id="ans1"/>
<input type="text" name="ans2" id="ans2"/>
<input type="text" name="ans3" id="ans3"/>
<input type="text" name="ans4" id="ans4"/>
When I want to Update the answers, How can I query ?
Thanks for answer my questiong 😀
You should have all the inputs along with a submit button inside the form tag. Also inside the form tag, have a hidden input which will contain the id of the question as value. When you click submit, it will post the all the inputs including the hidden input. In the processing page (form action page), get the value of the hidden input(you will need this in the where clause of your query). Then write an update query in the below way.
You definately dont want to update all the 4 answers but only one answer as every question will have only one answer.
Assuming your table name is questions:
Also it will be good if you can put a check if the user is not inputting all 4 answers through javascript.
Are you sure you need an update query and not an insert query ?
This can also be done through jquery (ajaxed way), but you didnt mention how you want to do it.