LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2004, 09:10 AM   #1
Erik Thorsson
Member
 
Registered: Jun 2004
Location: NYC
Distribution: Fedora Core 1
Posts: 64

Rep: Reputation: 15
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
 
Old 12-02-2004, 09:22 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,704

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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.
 
Old 12-03-2004, 07:35 AM   #3
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Rep: Reputation: 30
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)?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP - MySQL link StarLion Fedora 4 09-10-2005 11:05 AM
PHP & MYSQL => session object using db link resource ldp Programming 2 03-19-2005 02:38 AM
Updating Php & mysql dutchkillers Red Hat 1 07-12-2004 12:37 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
Updating php 4.3.1 from tar and keeping current php configuration with mandrake 9.1 mrjeep Linux - General 0 04-02-2003 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration