php - SQL 字符串不显示任何信息

标签 php mysql

我在一个旧网站上工作,试图完全重写它

我有以下 SQL 字符串,它在我的旧站点上有效,但将其带到新站点时我没有显示任何信息。

<table class="table">
                  <thead>
                    <tr>
                      <th width="13%">&nbsp;</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/

相关文章:

PHP正则表达式的单词短语语法?

php - WPDB 查询不适用于除表中的目标 id 之外的任何其他列?

mysql - 如何将 JSON 字符串加载到 JSON 列中

php - PHP 中的 if 语句将 json 条目映射到 mysql 数据库

php - 如何在 php 中使用 if else 语句将每隔一个数字替换为另一个数字?

php - 比较两个表如果重复列则更新,如果不匹配则插入

php - Zend framework 2/Doctrine 2/批量操作和事件触发

javascript - 简单的 javascript 调用失败

python - MysqlPython : Not all parameters were used in MySQL statement

mysql - 根据同一表上的两列选择单列的总和