visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: another stupid question


By: roe1and Great Britain  Date: 18/01/2008 12:44:19  English  Points: 20 Status: Answered
Quality : Excellent
i have a page that contains a form and it looks something like this :

[]name
[]surname
[]tel_no
[]birth_date
[]address
submit

the [] represents checkboxes

on the next page i want this information to go into a sql query. so if i select name and surname and address and submit it on the next page the query has to read "SELECT name, surname, address FROM ...".
or if i select name and birth_date then it needs to read "SELECT name, birth_date FROM ..."

i suppose id would be easiest to pass these into an variable and than place the variable in the query:

$fields = 'name, birth_date';

$query = "SELECT $fields FROM ...;";

i just cant seem to figure it out.... help please
By: VGR Date: 18/01/2008 15:02:02 English  Type : Answer
not tested but should work :

$query='select '; //note the space foreach($_POST as $var=>$val) { $query.="$var='{$val}' AND "; //note the spaces } if ($query=='select ') then die ("please check some boxes ;-)"); else { // go on // delete the last "and " //note the space $query=substr($query,0,-4); // complete query $query.="from ...;"; //note no space // exec etc }

By: roe1and Date: 18/01/2008 17:02:07 English  Type : Comment
i got it sorted in the end. my solution was not as elegant as yours but thanks anyway

Do register to be able to answer

EContact
browser fav
page generated in 92.263940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page