Loosing it

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Slawomir Piwowarczyk

    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.p hp 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($qu ery);
    while($row = mysql_fetch_row ($result)){
    print_r($row[0]);
    echo '<br>';
    ....


  • George

    #2
    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

    Comment

    • Pedro Graca

      #3
      Re: Loosing it

      Slawomir Piwowarczyk wrote:[color=blue]
      > <?
      > //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($qu ery);[/color]

      Because you don't check the return from mysql_query(). Try

      $result = mysql_query($qu ery) 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!

      Comment

      Working...