Forums

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

Home Forums Back End If ID does not exist? (PHP) Re: If ID does not exist? (PHP)

#95908
bungle
Member

In order to provide the latter functionality as crgeary says, when a user deletes their profile, you would really want to mark their user ids record as inactive rather than deleting it. I would add a boolean field of ‘active’ to the user table and then you can do a check like this to see what you are dealing with:


$id  = mysql_real_escape_string($_GET);
$sql = "SELECT * FROM users WHERE id=$id";
$result = mysql_query($sql);

if (mysql_num_rows($result)==0) {
echo ('User never existed');
}
else if (mysql_num_rows($result)==1) {
$userinfo = mysql_fetch_array($result);
if (!$userinfo) {
echo ('User no longer exists.');
}
else {
echo ('User exists and is active.')
}
}
?>