Results 1 to 5 of 5

Thread: Weird problem?

  1. #1
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Weird problem?

    So I am setting up a site, and need some help with the members list. For some odd reason, I get the error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/USERNAME/alpha/members.php on line 36

    Although, I didn't set this up any different than my other lists. Here is the code.

    PHP Code:
    <?php
    // Register your Members session
    session_start();

    // Connect to the Database
    $host="localhost"// Host name
    $dbusername="CENSORED"// Mysql username
    $dbpassword="CENSORED"// Mysql password
    $db_name="CENSORED"// Database name
    $tbl_name="members"// Table name

    // Connect to server and select databse.
    mysql_connect("$host""$dbusername""$dbpassword")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
    // OREDER BY id DESC is order result by descending
    $result=mysql_query($sql);
    ?>

    <!-- Call the Header -->
    <?php
    include('include/header.php');
    ?>

    <!-- Call the Navigation -->
    <?php
    include('include/navigation.php');
    ?>

    <div class="main">
    <h2>Members List</h2>
    <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
    <?php
    // Loop results
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><? echo $rows['username']; ?></td>
    </tr>
    <?php
    // Exit looping and close connection
    }
    mysql_close();
    ?>
    </table>
    </div>

    <!-- Call the Sidebar -->
    <?php
    include('include/sidebar.php');
    ?>

    <!-- Call the Footer -->
    <?php
    include('include/footer.php');
    ?>
    Any help is greatly appreciated.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    That most likely means that:
    1. Your connecting to the database has failed, or
    2. You're query doesn't make sence instead of:
    Code:
    $result=mysql_query($sql);
    Try:
    Code:
    $result=mysql_query($sql) or die(mysql_error());
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    The mysql_error seemed to help, but now its telling me that my table doesn't exist. :S

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try:
    Code:
    $sql="SELECT * FROM `'$tbl_name'` ORDER BY `id` DESC";
    If not, try:
    Code:
    $sql="SELECT * FROM `$tbl_name` ORDER BY `id` DESC";
    Or:
    Code:
    $sql="SELECT * FROM '$tbl_name' ORDER BY `id` DESC";
    Jeremy | jfein.net

  5. #5
    Join Date
    May 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well how is your database tables laid out?

    SQL statements are usually case sensitive so double check the name of the table.

    and I would try this

    PHP Code:
    $sql="SELECT * FROM " $tbl_name " ORDER BY `id` DESC"

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
  •