Jump to content

Problem with executing a query


hno

Recommended Posts

HI,

I have write a script and it's make a query like this:"SELECT * FROM `questions` WHERE  ( '1_1' = 1 or '1_1' = 2 ) and ( '1_2' = 1 ) and ( '1_3' = 1 or '1_3' = 2 ) and ( '1_4' = 1 or '1_4' = 2 ) "  but When I run it with php it gives me this error:"You have an error in SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" but When I copy the query to the phpmyadmin and run it manually it shoes me the rows.

What's the problem?Why phpmyadmin run the query successfully but php couldn't run it ?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/201504-problem-with-executing-a-query/
Share on other sites

Relevant!! We need to see where you assign a value to $q

 

I have a big form and I have to get many information .

i get them by using this code

 

for ($i=1;$i<=7;$i++){

for ($l=1;$l<=10;$l++){

$need_or=0;

$ok='';

$k='';

$first_time=1;

foreach($arr as $key=>$val){

if ($need_or)$k='or';

if ($_POST[$i .'_' . $l . '_' . $val]=='true'){

if ($first_time)$q.=' and ( ';

$q.=" $k '".  $i .'_' . $l . '\'' .' = ' .$key;

$need_or=1;

$first_time=0;

}

}

if ($first_time==0)$q.=' ) ';

}

}

$q{0}='';$q{1}='';$q{2}='';$q{3}='';

$q="SELECT * FROM `questions` WHERE $q ";

 

And then I run the query by using those codes.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.