By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

Loosing it

P: n/a
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>';
....
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 17 '05 #2

P: n/a
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!
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.