SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I've got three checkboxes on which i want to search for results in my database. Code:
    ---------------------------
    if ($submit) {

    if ($webmail | | $opstartcd | | $telnet) {
    $sql = "SELECT * FROM access WHERE ";

    if ($webmail)
    {$sql .= "webmail = '$webmail ";}

    if ($opstartcd)
    {if ($webmail) $sql .= "AND ";
    $sql .= "opstartcd = '$opstartcd ";}

    if ($telnet)
    {if ($webmail | | $opstartcd) $sql .= "AND ";
    $sql .= "telnet = '$telnet ";}

    $result = mysql_query($sql);
    {
    echo "<table border=1>
    ";
    echo "<tr><td>Bedrijf</td><td>Pakket</td><td>Type</td><td>Regio</td></tr>
    ";
    while ($myrow = mysql_fetch_array($result)){
    printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
    ",
    $myrow[bedrijf], $myrow[pakket], $myrow[type], $myrow[regio]);
    }}

    } else {
    echo("Oeps! None of the boxes selected.");
    }
    }
    ------------------------------------
    When i select a box and post the form i get the following error:

    Warning: Supplied argument is not a valid MySQL result resource in /opt/guide/www.webselect.nl/HTML/voorbeeld.php3 on line 30

    Line 30 is the following piece of code:
    while ($myrow = mysql_fetch_array($result))

    I don't see the problem. Do you?
    Great thanks,

    Joep

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. It looks as if you missed a single quote right after $opstartcd.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    if ($opstartcd)
    {if ($webmail) $sql .= "AND ";
    $sql .= "opstartcd = '$opstartcd' ";}
    [/code]

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You missed closing single quotes for each of your search values:

    if ($webmail)
    {$sql .= "webmail = '$webmail' ";}

    if ($opstartcd)
    {if ($webmail) $sql .= "AND ";
    $sql .= "opstartcd = '$opstartcd' ";}

    if ($telnet)
    {if ($webmail | | $opstartcd) $sql .= "AND ";
    $sql .= "telnet = '$telnet' ";}



    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  4. #4
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whenever I'm havnig trouble with SQL statements, I just print it out on the page and examine it rather than guess if it's the problem within the script. Like:
    echo "&lt;h1&gt;".$sql."&lt;/h1&gt;";

  5. #5
    SitePoint Member
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    That solves the problem.
    I'm a bit new to php and especially the "echo &lt;h1&gt;'$sgl etc. function is great.
    Greetings from The Netherlands. (a lot of wind and about 20 degrees Celcius &lt;= that's summer :-)

    Joep


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
  •