Jump to content

Archived

This topic is now archived and is closed to further replies.

Immortal55

MySQL Error

Recommended Posts

When I try and get this script to run:

[code]
<?

//View Artist List, links to profile.

          require_once('dbconnect.php');
          $conn = db_connect();
          $db = @mysql_select_db ("mitchand_studio", $conn)
              or die ("Registration failure, try again.");
    
    $sql = mysql_query("SELECT * FROM users ORDER BY id DESC");

//the above line would get all your users, and order them by their Id's
// the loop below would then make a link for every user
        
    while($row = mysql_fetch_assoc($sql))
    {
    stripslashes(extract($row));
    
    echo '<a href="/profile/profile.php?user='.$uname.'>'.$uname.'</a>';
    
}

?>
[/code]

I get this error: [b]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/mitchand/public_html/users.php on line 15[/b]

What is wrong?

Share this post


Link to post
Share on other sites
[code]

<?

//View Artist List, links to profile.

          require_once('dbconnect.php');
          $conn = db_connect();
          $db = @mysql_select_db ("mitchand_studio", $conn)
              or die ("Registration failure, try again.");
    
    $sql = mysql_query("SELECT * FROM users ORDER BY id DESC");

//the above line would get all your users, and order them by their Id's
// the loop below would then make a link for every user
        
    while($row = mysql_fetch_array($sql))
    {
    stripslashes($row);
    
    echo '<a href="/profile/profile.php?user='.$row['uname'].'>'.$row['uname'].'</a>';
    
}

?>

[/code]

Share this post


Link to post
Share on other sites
That error means there is something wrong with your query. change this line:

[code]$sql = mysql_query("SELECT * FROM users ORDER BY id DESC");[/code]

to:

[code]$sql = mysql_query("SELECT * FROM users ORDER BY id DESC") or die(mysql_error());[/code]

then let us know what the error is.

Share this post


Link to post
Share on other sites
Ah, alright I fixed it, i did not have an id column.....

But now I have it ordering by name:

[code]
$sql = mysql_query("SELECT * FROM users ORDER BY name DESC") or die(mysql_error());
[/code]

it shows every member in the DB except the newest added member. So if I have 3 members in the DB only two are shown in the list, if i add a new member, only 3 are show on the list...

Why is this?

Share this post


Link to post
Share on other sites
[a href=\"http://www.mitchanderson.zenaps.com/users.php\" target=\"_blank\"]http://www.mitchanderson.zenaps.com/users.php[/a]

there is a link to my problem......There are 3 users in the table as of now they are, sadf, Mitch, and dtdt. Now Sadf shows up fine, the link and all, then Mitch shows up, but the link to his profile is all messed up, and dtdt dosent show up at all.....what is wrong???

Share this post


Link to post
Share on other sites
change:

[code]echo '<a href="/profile/profile.php?user='.$row['uname'].'>'.$row['uname'].'</a>';[/code]

to:

[code]echo "<a href=\"/profile/profile.php?user=" . $row['uname'] . "\">" . $row['uname'] . "</a>";[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.