Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Members Page (SELECT) Error!

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36370
    schart
    Participant

    So this is my code:


    $connect = mysql_connect("host", "username", "password");
    $select_db = mysql_select_db("database", $connect);
    if(!$select_db){
    die(mysql_error());
    }

    $write = mysql_query("SELECT username FROM husers");

    ?>
    The users are:


    The result is:

    “The users are: Resource id #3”

    What am I doing wrong?
    Oh, and please note that I don’t know PHP at ALL. This is basically a mix up of codes and tuts I found around the web, that weren’t working and my logic.

    My desire:
    To list all of the “username”s in the table “husers” on the page.

    #95634
    Thoven78
    Member

    The reason why you’re getting “The users are: Resource id #3” is because whenever you do a query you always have to fetch the table. This is what the code should have looked like.



    < ?php
    $connect = mysql_connect("host", "username", "password");
    $select_db = mysql_select_db("database", $connect);
    if(!$select_db){
    die(mysql_error());
    }

    $write = mysql_query("SELECT username FROM husers");
    $users = "";
    while ($row = mysql_fetch_assoc($write)) {
    $users = $row;
    }
    ?>


    #95644
    Thoven78
    Member

    Then you would have to do this.



    < ?php
    $connect = mysql_connect("host", "username", "password");
    $select_db = mysql_select_db("database", $connect);
    if(!$select_db){
    die(mysql_error());
    }

    $write = mysql_query("SELECT username FROM husers");
    $users = "";
    while ($row = mysql_fetch_assoc($write)) {
    $users .= "
  • " . $row . "
  • ";
    }
    ?>




    #95647
    Thoven78
    Member

    I forgot to close the li tag, make sure you close it.
    EDIT: I updated the code to close the li tag.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.