简体   繁体   English

mysql_num_rows()错误

[英]mysql_num_rows() Error

<html>
<form action="update.php" method="POST" name="ID">
<input type="text" name="ID"">
<input type="Submit" value="Submit">
</form>
</html>

Up there is the submit form to get an ID number. 上面有提交表单以获取ID号。 I try to get that ID entered by user ( NOTE: It's a number) and show mysql table row coresponding to that ID. 我尝试让用户输入该ID(注意:这是一个数字),并显示与该ID对应的mysql表行。 Example : User enter 2 and row number 2 from database is shown. 示例:用户输入2,显示数据库中的行号2。 My problem is that all rows are shown and not only wanted one. 我的问题是显示了所有行,而不仅仅是想要一个。 - Extra Question : How can I show user an error if he entered a NULL value ? -额外问题:如果用户输入NULL值,如何显示错误?

<?php
    $id=$_POST['ID'];
    .
    .
    .
    mysql_connect($host,$username,$password);

    if (!mysql_select_db($database))
        die("Can't select database");
    $query="SELECT * FROM table WHERE ID= '$id'";
    $result = mysql_query("SELECT * FROM vbots");
    $num=mysql_num_rows($result) or die("Error: ". mysql_error(). " with query ". $query);

    mysql_close();
    .
    .
    .
?>

You're not running your query. 您没有运行查询。

You have this: 你有这个:

$query="SELECT FROM table WHERE ID= '$id'";
$result = mysql_query("SELECT * FROM vbots");

You want this: 你要这个:

$query="SELECT FROM table WHERE ID= '$id'";
$result = mysql_query( $query);

** Insert nag about SQL injection ** ** 插入有关SQL注入的内容 **

It should be this. 应该是这个

<?php
$id=$_POST['ID'];

mysql_connect($host,$username,$password);

if (!mysql_select_db($database))
    die("Can't select database");
$query="SELECT * FROM table WHERE ID= '$id'";
$result = mysql_query($query);
$num=mysql_num_rows($result) or die("Error: ". mysql_error(). " with query ". $query);

mysql_close();
?>

检查$ id是否为空:if(!isset($ id))die(“输入ID值!”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM