mysql_db_query(): PROBLEM

Discussion in 'PHP' started by Kurt Whittingham, Mar 13, 2012.

  1. #1
    hello.

    i got this error
    Warning: mysql_db_query(): supplied argument is not a valid MySQL-Link resource in /home/motorbik/public_html/cat page.php on line 49

    here is my code
    <?php
        $categories = "Gear Reviews";
    
        // setup SQL statement
        $SQL = " SELECT * FROM Gear Reviews ";
        $SQL = $SQL . " WHERE categories = '$categories' ";
    
        // execute SQL statement
        $retid = mysql_db_query($db, $SQL, $cid);
    
        // check for errors
        if (!$retid) { echo( mysql_error()); }
        else {
    
            // display results
            echo ("<p><dt><b>$categories</b><br>\n");
            while ($row = mysql_fetch_array($retid)) {
                $url = $row["url"];
                $name = $row["name"];
                $description = $row["description"];
                
                echo ("<p><a href='$url'>$name</a></p>\n");
            }
            echo ("</dt></p>");
        }
    ?>
    PHP:
     
    Kurt Whittingham, Mar 13, 2012 IP
  2. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #2
    I think the error is in one of the lines
    
    $SQL = " SELECT * FROM Gear Reviews ";
    $SQL = $SQL . " WHERE categories = '$categories' ";
    
    PHP:
    Why don't you simplify the query
    
    $SQL = "SELECT * FROM Gear Reviews WHERE categories = '$categories'";
    
    PHP:
    I think also that 'categories' is a RESERVED word in MySql, try to rename your table field...
     
    dujmovicv, Mar 13, 2012 IP
  3. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #3
    okay i changed the table to categ.

    and got this error now
    Warning: mysql_db_query(): supplied argument is not a valid MySQL-Link resource in /home/motorbik/public_html/cat page.php on line 48


    this is the code changed
    <?php
        $categ = "Gear Reviews";
    
        // setup SQL statement
        $SQL = "SELECT * FROM Gear Reviews WHERE categ = '$categ'";
    
        // execute SQL statement
        $retid = mysql_db_query($db, $SQL, $cid);
    
        // check for errors
        if (!$retid) { echo( mysql_error()); }
        else {
    
            // display results
            echo ("<p><dt><b>$categ</b><br>\n");
            while ($row = mysql_fetch_array($retid)) {
                $url = $row["url"];
                $name = $row["name"];
                $description = $row["description"];
                
                echo ("<p><a href='$url'>$name</a></p>\n");
            }
            echo ("</dt></p>");
        }
    ?>                            
    
    PHP:
     
    Kurt Whittingham, Mar 13, 2012 IP