简体   繁体   English

php / mySQL错误:mysql_num_rows():提供的参数不是有效的MySQL结果

[英]php/mySQL error: mysql_num_rows(): supplied argument is not a valid MySQL result

I'm trying to INSERT INTO a mySQL database and I'm getting this error on: 我正在尝试插入一个mySQL数据库,我收到此错误:

if (mysql_num_rows($login) == 1){

Here is the php, The php does add the user to the database. 这是php,php确实将用户添加到数据库中。 I can't figure it out. 我无法弄清楚。

<?
session_start();
require("config.php");

$u = $_GET['username'];
$pw = $_GET['password'];
$pwh = $_GET['passwordhint'];
$em = $_GET['email'];
$zc = $_GET['zipcode'];


$check = "INSERT INTO family (loginName, email, password, passwordhint, location) VALUES ('$u', '$pw', '$pwh', '$em', '$zc')";


$login = mysql_query($check, $link) or die(mysql_error());


if (mysql_num_rows($login) == 1) {
$row = mysql_fetch_assoc($login);
echo 'Yes';exit;


} else {
echo 'No';exit;
}

mysql_close($link);
?>

Thanks, 谢谢,

You're doing an INSERT query, so $login won't contain any result set, it's either true or false . 您正在执行INSERT查询,因此$login将不包含任何结果集,它可以是truefalse

So instead of this: 所以不是这样的:

if (mysql_num_rows($login) == 1) {

You can either do this: 你可以这样做:

if (mysql_affected_rows($link) == 1) {

Or this: 或这个:

if ($login == true) {

Also, you don't need this line anymore: 此外,您不再需要此行:

$row = mysql_fetch_assoc($login);

Unrelated to your question, but a very important thing to remember when doing SQL queries: you'll need to escape all your $_GET data with mysql_real_escape_string() just before inserting, so as to prevent SQL injection . 与您的问题无关,但在进行SQL查询时要记住这一点非常重要:在插入之前,您需要使用mysql_real_escape_string()转义所有$_GET数据,以防止SQL注入

mysql_query()为INSERT,UPDATE,DELETE,DROP返回True / False ...

暂无
暂无

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

相关问题 PHP错误:mysql_num_rows():提供的参数不是有效的MySQL结果 - PHP error: mysql_num_rows(): supplied argument is not a valid MySQL result mysql_num_rows():提供的参数不是有效的MySQL结果资源 - mysql_num_rows(): supplied argument is not a valid MySQL result resource 警告mysql_num_rows():提供的参数不是有效的MySQL结果 - Warning mysql_num_rows(): supplied argument is not a valid MySQL result mysql_num_rows():提供的参数不是有效的MySQL结果资源 - mysql_num_rows(): supplied argument is not a valid MySQL result resource 警告:mysql_num_rows():提供的参数不是没有mysql_error()的有效MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource with no mysql_error() 如何解决mysql_num_rows():提供的参数不是PHP中的有效MySQL结果资源 - How to solve mysql_num_rows(): supplied argument is not a valid MySQL result resource in php 修复错误:mysql_num_rows():提供的参数不是有效的MySQL结果资源 - Fixing the error: mysql_num_rows(): supplied argument is not a valid MySQL result resource 帮助 我在使用 PHP 时收到一条错误消息“警告:mysql_num_rows():提供的参数不是有效的 MySQL 结果资源...” - Help I have an error message using PHP “Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in…” 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM