Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅显示查询的ID+行PHP/MySQL_Php_Mysql - Fatal编程技术网

仅显示查询的ID+行PHP/MySQL

仅显示查询的ID+行PHP/MySQL,php,mysql,Php,Mysql,我的数据存储在一个MySQL表中,该表包含一个自动增量ID号,每个新行都是唯一的 我希望用户能够使用$\u get函数获得特定的ID号 例如,用户负载 页面显示ID号123以及行 echo $row['id']; echo "<table>"; echo "<tr> <th>Unit</th> <th>Message</th> <th>Date</th> </tr>"; while($ro

我的数据存储在一个MySQL表中,该表包含一个自动增量ID号,每个新行都是唯一的

我希望用户能够使用$\u get函数获得特定的ID号

例如,用户负载 页面显示ID号123以及行

echo $row['id'];
echo "<table>";
echo "<tr> <th>Unit</th> <th>Message</th> <th>Date</th> </tr>";
while($row = mysql_fetch_array( $result )) {

echo "<tr><td>";
echo $row['title'];
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
echo $row['pubDate'];
echo "</td></tr>";

}
echo "</table>";
echo "</center>";
我被困在哪里,我把你得到的美元位


谢谢:

您应该使用将其附加到查询中,以避免像这样的SQL注入:

// use the id in your WHERE clause, convert it to an integer to avoid sql injections
$query = 'SELECT fields FROM table WHERE id = ' . intval($_GET['id']);

$result = mysql_query($query);
$row = mysql_fetch_row($result);

... do stuff with $row ...
$id     = intval($_GET['id']);
$result = mysql_query("SELECT FROM table WHERE id = '$id'");

应使用将其附加到查询中,以避免SQL注入,如下所示:

// use the id in your WHERE clause, convert it to an integer to avoid sql injections
$query = 'SELECT fields FROM table WHERE id = ' . intval($_GET['id']);

$result = mysql_query($query);
$row = mysql_fetch_row($result);

... do stuff with $row ...
$id     = intval($_GET['id']);
$result = mysql_query("SELECT FROM table WHERE id = '$id'");

首先,您的代码没有多大意义,因为您在定义$row之前使用了它

其次,$result根本没有定义,它应该是这样的,例如:

// use the id in your WHERE clause, convert it to an integer to avoid sql injections
$query = 'SELECT fields FROM table WHERE id = ' . intval($_GET['id']);

$result = mysql_query($query);
$row = mysql_fetch_row($result);

... do stuff with $row ...
$id     = intval($_GET['id']);
$result = mysql_query("SELECT FROM table WHERE id = '$id'");

现在您知道了如何以及在何处使用$_GET['id'])。

首先,您的代码没有多大意义,因为您在定义$row之前使用了它

其次,$result根本没有定义,它应该是这样的,例如:

// use the id in your WHERE clause, convert it to an integer to avoid sql injections
$query = 'SELECT fields FROM table WHERE id = ' . intval($_GET['id']);

$result = mysql_query($query);
$row = mysql_fetch_row($result);

... do stuff with $row ...
$id     = intval($_GET['id']);
$result = mysql_query("SELECT FROM table WHERE id = '$id'");

现在您知道了如何以及在何处使用$\u GET['id')。

以后不要浪费时间进行比较,将其添加到原始查询中可以节省大量时间

$id = intval($_GET['id']);
$query = "SELECT whatever FROM table WHERE id=$id";

不要浪费时间在后面进行比较,将其添加到原始查询中可以节省大量时间

$id = intval($_GET['id']);
$query = "SELECT whatever FROM table WHERE id=$id";

@Dominic Rodger PHP有时很奇怪;。谢谢你的编辑@Dean-在设置$row之前,您仍然在使用它。您在第14行使用它,它在第17行设置。@Dominic Rodger PHP有时很奇怪;。谢谢你的编辑@Dean-在设置$row之前,您仍然在使用它。您在第14行使用它,它在第17行设置。yourpage.com?id=';从表中删除*;从id='3的表中选择*此查询将不起作用,因为数据和字段是转义的。yourpage.com?id=';从表中删除*;从id='3的表中选择*这个查询将不起作用,因为数据和字段都是转义的。我只放了一小部分,它是在前面定义的。我只放了一小部分,它是在前面定义的。是的,我就是这么想的。但是我想不出怎么把它放进去。谢谢你的精心设计。是的,我就是这么想的。但是我想不出怎么把它放进去。谢谢你的详细说明。