如果ID在表中不存在,为什么不将用户发送到user.php ?
<?php
include 'db_connect.php';
$id_exists = false;
$url_id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT id FROM members WHERE id='$url_id'";
$result = mysql_query($sql);
if ($result == $url_id)
{
$id_exists = true;
}
else if ($result != $url_id)
{
$id_exists = false;
header("location:user.php");
exit();
}
?>
$url_id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT id FROM members WHERE id='$url_id'";
$result = mysql_query($sql);
if(mysql_num_rows($result) >0){
//found
}else{
//not found
}
试试这样做:)。http://php.net/manual/en/function.mysql-num-rows.php
请阅读mysql_query
的文档。您必须在进行查询后获取结果。也就是说,您应该使用PDO而不是mysql_*
。
因为mysql_query不返回一行,它返回一个资源。
使用mysql_num_rows($result)
检查是否有行返回