Loosing it

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 &...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2005
Slawomir Piwowarczyk
 
Posts: n/a
Default Loosing it

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>';
....


Reply With Quote
  #2 (permalink)  
Old 01-08-2005
George
 
Posts: n/a
Default Re: Loosing it

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

Reply With Quote
  #3 (permalink)  
Old 01-08-2005
Pedro Graca
 
Posts: n/a
Default Re: Loosing it

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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0