Updating MySQL DB when a link is clicked with PHP
I've got a PHP/MySQL setup.
I have a page where I want to place the user's selection between two values ('yes' and 'no' in this case) into the database based on which link they click. Is there a way to do that from code on that page, or do I have to link two different .php pages (e.g. y.php and n.php) which will then do their respective additions to the database. Seems like there should be a better way, because what if there were six options instead of two? Is that what all the ?=&action=newthread&forumid=9 stuff is in the URL at right now? A way to transmit variables to another page through a link? What does the <a href=... tag look like? -E |
You can add the code to the same web page that will post the response to the database. You would use a form and submit back to the same page. I don't have time to post code at the momemt but you can find examples on the web.
|
If your page is evaluate.php, it will look something like this:
<a href="./evaluate.php?param=y">yes</a> <a href="./evaluate.php?param=n">no</a> your php code (best in the beginning of the page) will then be: $param = $HTTP_GET_VARS[param]; if (isset($param)) { // update selection in the database here } One last remark: this way you will go to the database every time you click on yes or no. Seems inefficient to me. Why not wait to do this until the user leaves the page (preferably through a submit button)? |
All times are GMT -5. The time now is 01:22 PM. |