Php 从表中调用的ID
我有一个ads表,有一个Id列,它的值为Int 这是一张保存会员需要浏览的广告的表格 会员每24小时只能浏览一次广告 ,当会员点击“浏览广告”按钮时,他将按Id顺序浏览广告 为会员显示的链接广告示例 mysite com/surfing.php?area=ad&id=8 如果手动将Id值从url链接而不是从表中更改为任何数字,则会出现问题示例:5478965324 mysite com/surfing.php?area=ad&id=5478965324 这个数字不在Id列中 但是URL工作并认为这是ID/P>Php 从表中调用的ID,php,mysql,Php,Mysql,我有一个ads表,有一个Id列,它的值为Int 这是一张保存会员需要浏览的广告的表格 会员每24小时只能浏览一次广告 ,当会员点击“浏览广告”按钮时,他将按Id顺序浏览广告 为会员显示的链接广告示例 mysite com/surfing.php?area=ad&id=8 如果手动将Id值从url链接而不是从表中更改为任何数字,则会出现问题示例:5478965324 mysite com/surfing.php?area=ad&id=5478965324 这个数字不在Id列中 但是URL工作并认为
$id=$_GET[id];
if ($id == '') {header("location: surfing.php"); exit;}
if ($id != '0') {$ad_info=mysql_fetch_array(mysql_query("SELECT * FROM ads where id=$id"));}
if ($id == '0') {$collect=mysql_fetch_array(mysql_query("SELECT * FROM config"));$ad_info[link]=$collect['url'];}
if ($id == '0') {$frame1="surfing.php?area=msg&msg=1";} else {$frame1="surfing.php?area=top&&id=$id";}
if ($id == '0') {$ad_temp="<frame src='$frame1' noresize=noresize>";}
现在通过以下方式检查是否存在:
if ( mysqli_num_rows($result) < 1 )
{
// handle error here..
}
您需要发出计数查询
$id = $_GET['id'];
if (is_numeric($id)) {
$result = mysql_query("SELECT * FROM table WHERE id = '$id'");
if (mysql_num_rows($result) > 0) {
# do your stuff
} else {
# no rows found.
}
}
另外,不建议使用mysql_*函数。相反,您可以使用mysqli_*of pdo函数来实现相同的功能。您需要使用id发出select查询,并检查其是否存在于表中
$id = $_GET['id'];
if (is_numeric($id)) {
$result = mysql_query("SELECT * FROM table WHERE id = '$id'");
if (mysql_num_rows($result) > 0) {
# do your stuff
} else {
# no rows found.
}
}