Jump to content

help with if statement


MDanz

Recommended Posts

how do i say if user doesn't exist.  that below shows the avatar correctly for the user posting. How do i do if the user doesn't exist from the database?

 

$useravatar = mysql_query("SELECT * FROM Users WHERE username='$username1'")or die (mysql_error());

while($row5 = mysql_fetch_array($useravatar)){

  $image = $row5['avatar'];

  }

Link to comment
https://forums.phpfreaks.com/topic/191931-help-with-if-statement/
Share on other sites

Your actual question makes little sense but you should always be checking you optained a record before using it anyway. eg;

 

if ($result = mysql_query("SELECT avatar FROM Users WHERE username='$username1'") {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    $image = $row['avatar'];
  } else {
    // no record found.
  }
} else {
  trigger_error(mysql_error());
}

Archived

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

×
×
  • Create New...

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.