www.webdeveloper.com
Results 1 to 7 of 7

Thread: Warning:mysql_query() & mysql_fetch_array()

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Warning:mysql_query() & mysql_fetch_array()

    Hi . I need help

    Warning: mysql_query() expects parameter 2 to be resource, null given in Z:\home\localhost\www\sayt\index.php on line 3

    Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in Z:\home\localhost\www\sayt\index.php on line 4

    <?php
    include ("blocks/bd.php");
    $result = mysql_query("SELECT title,meta_d,meta_k,text FROM settings WHERE page='index'",$db);
    $myrow = mysql_fetch_array($result);
    ?>

    what is wrong ?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,432
    Where do you do your mysql_connect(), presumably assigning the result to $db? Did you verify it worked before trying to use it later?

    Assuming it was supposed to be done in the block/bd.php file, is that the correct file name? Should it be require()'d instead of include()'d in order to be positive it gets loaded?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2012
    Location
    serbia
    Posts
    62
    you have to put @mysql_fetch_array($result); ---- @ before mysql_fetch_array($result);

  4. #4
    Join Date
    Sep 2012
    Location
    serbia
    Posts
    62
    $result = @mysql_query("SELECT title,meta_d,meta_k,text FROM settings WHERE page='index'",$db);

  5. #5
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Don't use the @ symbol. It only suppresses errors, it does nothing to resolve them (in fact it makes them harder to resolve since it hides the error messages meaning you can't find where it went wrong).

    What needs to be checked is that $db is properly being assigned to a mysql connection resource. One thing i notice is that your file I would assume is where mysql_connect is, is named bd.php not db. If $db is not assigned to something it will be null (hence the error). One that's null the query funtion fails to even execute because of invalid parameters, meaing $result will be undefined. Since its undefined, you get the second error as you end up passing null to mysql_fetch_array.

    Note: The entire mysql_* extension is marked for deprecation and it is strongly suggested you use PDO or mysqli_* instead.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  6. #6
    Join Date
    Sep 2012
    Location
    serbia
    Posts
    62
    just try @

  7. #7
    Join Date
    Sep 2012
    Location
    serbia
    Posts
    62
    $result = @mysql_query("SELECT title,meta_d,meta_k,text FROM settings WHERE page='$index'",$db);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles