This is a discussion on Loosing it within the PHP Language forums, part of the PHP Programming Forums category; two words from the form below and one simple query after, doesnt work, what to do to make it work &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
two words from the form below and one simple query after, doesnt work, what
to do to make it work <FORM ACTION=search.php METHOD=POST> <INPUT TYPE=TEXT NAME=search size=20> <INPUT TYPE=TEXT NAME=search1 size=20> <INPUT TYPE="submit" VALUE="Proceed query"> </FORM> <? //this one works fine: "select * from table_1 where dane like '%$search%'" //but i wanna the one below to work $query = "select * from table_1 where dane (like '%$search%') or dane (like '%search1%')"; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ //DOESNT WORK, WHY? $result = mysql_query($query); while($row = mysql_fetch_row($result)){ print_r($row[0]); echo '<br>'; .... |
|
|||
|
Hi,
$query = "select * from table_1 where dane (like '%$search%') or dane (like '%search1%')"; well first of all you dont have $ in front of the search1 variable. also, why put the brackets there? this should be: $query = "select * from table_1 where dane like '%$search%' or dane like '%search1%'"; not only that, but this query should be further improved to: $query = "select * from table_1 where dane like '%".$search."%' or dane like '%".$search1."%'"; and you should always make sure that the variables you pass into the query are escaped (the default setting of magic quotes varies from host to host). George |
|
|||
|
Slawomir Piwowarczyk wrote:
> <? > //this one works fine: "select * from table_1 where dane like '%$search%'" > //but i wanna the one below to work > $query = "select * from table_1 where dane (like '%$search%') or dane (like > '%search1%')"; > //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ > ^^^^^^^^^^^^^^^^ > //DOESNT WORK, WHY? > > $result = mysql_query($query); Because you don't check the return from mysql_query(). Try $result = mysql_query($query) or die('Bad query: ' . mysql_error()); You could also try to make $query have a valid syntax. Hint: the parenthesis are badly positioned. -- Mail to my "From:" address is readable by all at http://www.dodgeit.com/ == ** ## !! ------------------------------------------------ !! ## ** == TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>) may bypass my spam filter. If it does, I may reply from another address! |