faqts : Computers : Programming : Languages : PHP : kms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 3 people (67%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

Is there a way to use data passed from a form in a SELECT statement?

Feb 2nd, 2004 08:15
Michael Felt, Randy Carlile,


It is actually quite simple.

The basic steps are:
1) connect to a database table
2) create queries (e.g. SELECT statements)
3) process the statements

To get data from a form (assuming POST for the moment)

$my_a = $HTTP_POST_VARS(['form_a']);

or using a GET syntax:

$my_a = $HTTP_GET_VARS(['form_a']);

a select statement can be made from:

$sql = "SELECT a,d,e,f FROM my_table WHERE a > $my_a AND a <= $my_b";

$result = mysql_query($sql);

while ($row = mysql_fetch_object($result)) {
   // do something nice with returned variables
   // $row->d, $row->e $row->f
}