我在一个旧网站上工作,试图完全重写它
我有以下 SQL 字符串,它在我的旧站点上有效,但将其带到新站点时我没有显示任何信息。
<table class="table">
<thead>
<tr>
<th width="13%"> </th>
<th width="13%">Cell Number</th>
<th width="15%">Requested By</th>
<th width="13%">Send to</th>
<th width="45%">Description</th>
</tr>
</thead>
<tbody>
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM lbs_trace_etrack WHERE id='$id'");
?>
<?php
while($rows=mysql_fetch_array($result)){
?>
<td><p>
<input name="lbs_msisdn" type="text" id="lbs_msisdn" value="<? echo $rows['lbs_msisdn']; ?>" size="12">
</p>
<p>
<input type="text" name="lbs_station" id="lbs_station" value="<? echo $rows['lbs_station']; ?>">
</p>
</td>
<?php } ?>
</tbody>
</table>
我发送了 id,它在 URL 中如下:
iframe/retrace.php?id=39661
用户名、密码和登录详细信息都正常,并且可以正确登录到数据库。
编辑: 在上一页中,我使用以下按钮链接
onClick="location.href='retrace.php?id=<? echo $rows['id']; ?>'"
最佳答案
" I added the following $id = $_GET['id'] ; This then pulls the id for me. Thanks to Fred-ii- – James Wright 2 mins ago"
正如我在评论中所述,$_GET
数组 $_GET['id']
从未设置或分配给它一个变量,因为您正在使用retrace.php?id
.
顺便说一句,您的代码对 SQL 注入(inject)开放。使用准备好的语句。
SQL 注入(inject):
此外,如果可能的话,请考虑重构您的代码以使用 MySQLi_ 或 PDO API:
关于php - SQL 字符串不显示任何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41397072/