php - 从表中调用 ID

标签 php mysql

我有广告表,并且该表中有包含 Int 值的 Id 列 这是保存成员(member)需要浏览的广告的表格 成员(member)每 24 小时只能浏览每个广告 ,当成员(member)点击浏览广告按钮时,他将按Id浏览广告DESC顺序

将为成员(member)展示的链接广告示例

我的网站 com/surfing.php?area=ad&id=8

如果我将 ID 值从 url 链接(而不是从表中)手动更改为任何数字示例,则会出现问题:5478965324

我的网站 com/surfing.php?area=ad&id=5478965324

这个数字不在 ID 列中 但 url 有效,并将其视为 Id

$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>";}

最佳答案

$id = $_GET['id'];
$results = mysqli_query($con, "SELECT * FROM table WHERE id = '{$id}'");   

现在检查是否存在:

if ( mysqli_num_rows($result) < 1 ) 
{
   // handle error here..
} 

关于php - 从表中调用 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25231862/

相关文章:

php - 当jquery-file-upload中的DB值 "position"等于 "id"时,如何插入数据

php - 如果零后为空,为什么要选择选项值

mysql - 如何找到 MySQL 记录集中的 ID 间隙?

jquery - 为 jquery 文件上传脚本创建 jpeg 图像数据

php - 是否可以模拟 PHPUnit 中不存在的函数?

php - 2 Mysql查询行数和主查询?

php - 如何实现输出id和更新表

php - 如何检查 Moodle 中是否设置了 required_pa​​ram?

mysql - 如何让最小和最大日期更小等于今天mysql

mysql select sql 很慢,哪个索引丢了