SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Location
    United Kingdom
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ya

    I have a problem with this bit of code (edited out stuff that isn't relevent)
    PHP Code:
     $mysql_database_reviews "wildwayz_reviews";
     
    $mysql_username  "someuser";
     
    $mysql_password  "somepassword";

    function 
    SearchReviews($query)
    {
     
    mysql_connect("localhost","$mysql_username","$mysql_password");
     
    mysql_select_db($mysql_database_reviews);

     
    $tbuf $buffer;

     
    $res mysql_query("SELECT * FROM reviews WHERE title like '%$query%' OR actors like '%$query%'") or die("Main error");
     
    $num mysql_num_rows($res);

    The error I get is "Main Error" - I checked that before the "$res = mysql_query....." is executed that the value of $query is fine - and it is.

    What I am doing is trying to get a search working for my review database which is sent through a form.

    It works fine for my news database (values changed though)
    PHP Code:
     $res mysql_query("SELECT * FROM news WHERE headline like '%$query%' or preview like '%$query%' or tekst like '%$query%'") or die("Main error"); 
     
    $num mysql_num_rows($res); 
    and that works fine, but not the first one

    Any ideas?

    James

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem is that you are trying to use vars that were established outside the funation and not globalized inside the function try
    PHP Code:
    $mysql_database_reviews "wildwayz_reviews";
     
    $mysql_username  "someuser";
     
    $mysql_password  "somepassword";

    function 
    SearchReviews($query)
    {
    global 
    $mysql_database_reviews$mysql_username$mysql_password;
     
    mysql_connect("localhost","$mysql_username","$mysql_password");
     
    mysql_select_db($mysql_database_reviews);

     
    $tbuf $buffer;

     
    $res mysql_query("SELECT * FROM reviews WHERE title like '%$query%' OR actors like '%$query%'") or die("Main error");
     
    $num mysql_num_rows($res);

    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •