这个查询有什么问题?
我正在尝试定义一个用户注册类,这是我现在拥有的功能
<?php
///// SE SUPONE QUE AQUI EL USUARIO YA HA INTRODUCIDO SUS DATOS DE REGISTRO
/* Conectando la Base de Datos */
include("includes/basedatos.php");
require_once("includes/funciones.php");
class registro_usuarios
{
var $pass;
var $email;
var $nombre;
public function tratandovariables()
{
/* Eliminando Caracteres Especiales */
$password = htmlspecialchars($_POST['pass']);
$mail = htmlspecialchars(strip_tags($_POST['mail']));
$nombre = htmlspecialchars(strip_tags($_POST['nombre']));
if (preg_match("/^[a-zA-Z0-9\-_]{3,20}$/", $nombre))
{
/* Asignando Valor */
$this->pass = md5($password);
$this->email = $mail;
$this->nombre = $nombre;
}
else
{
echo "El nombre de usuario no es válido<br>";
exit;
}
}
public function register()
{
$this->tratandovariables();
/* Comprobando si existe el usuario */
$check = "SELECT * FROM usuarios WHERE alias = '$this->nombre'";
$qry = mysql_query($check);
/* La compracion */
if (mysql_num_rows($qry))
{
echo "Lo sentimos, el nombre de usuario ya esta registrado.<br />";
mysql_free_result($qry);
return false;
} else
{
$insert = "INSERT INTO usuarios (alias, pass, email, fid, fechar, ultima, img_src, reputacion) VALUES ('".$this->nombre."','".$this->pass."','".$this->email."','-1', 'NOW()', 'NOW()',' ', '0' )";
$qry = mysql_query($insert);
if(mysql_affected_rows())
{
echo "El Usuario $this->nombre se Registro Correctamente";
return true;
}
else
{
echo "Error Ingresando datos";
return false;
}
return false;
}
}
}
?>
,问题是我总是给出这个错误(通过没有奇怪字符的表单输入一个简单的varchar):
警告: mysql_fetch_array():提供的参数不是 /home/piscolab/public_html/keepyourlinks.com/Recetas/registro.php 第 52 行中的有效 MySQL 结果资源 El Usuario toni se Registro Correctamente
- $this->nombre 有一个非空值(选中)
- 数据库为空,因此不应该有结果。
- 问题是脚本继续并假装用户已注册,甚至显示名称!并且数据库没有更新..
我只是看不到问题..你能吗?
谢谢你!
i'm trying to define a User registration class and this is the function i have for now
<?php
///// SE SUPONE QUE AQUI EL USUARIO YA HA INTRODUCIDO SUS DATOS DE REGISTRO
/* Conectando la Base de Datos */
include("includes/basedatos.php");
require_once("includes/funciones.php");
class registro_usuarios
{
var $pass;
var $email;
var $nombre;
public function tratandovariables()
{
/* Eliminando Caracteres Especiales */
$password = htmlspecialchars($_POST['pass']);
$mail = htmlspecialchars(strip_tags($_POST['mail']));
$nombre = htmlspecialchars(strip_tags($_POST['nombre']));
if (preg_match("/^[a-zA-Z0-9\-_]{3,20}$/", $nombre))
{
/* Asignando Valor */
$this->pass = md5($password);
$this->email = $mail;
$this->nombre = $nombre;
}
else
{
echo "El nombre de usuario no es válido<br>";
exit;
}
}
public function register()
{
$this->tratandovariables();
/* Comprobando si existe el usuario */
$check = "SELECT * FROM usuarios WHERE alias = '$this->nombre'";
$qry = mysql_query($check);
/* La compracion */
if (mysql_num_rows($qry))
{
echo "Lo sentimos, el nombre de usuario ya esta registrado.<br />";
mysql_free_result($qry);
return false;
} else
{
$insert = "INSERT INTO usuarios (alias, pass, email, fid, fechar, ultima, img_src, reputacion) VALUES ('".$this->nombre."','".$this->pass."','".$this->email."','-1', 'NOW()', 'NOW()',' ', '0' )";
$qry = mysql_query($insert);
if(mysql_affected_rows())
{
echo "El Usuario $this->nombre se Registro Correctamente";
return true;
}
else
{
echo "Error Ingresando datos";
return false;
}
return false;
}
}
}
?>
And the problem it's that i'm allways given this error (entering a simple varchar through a form with no weird chars):
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/piscolab/public_html/keepyourlinks.com/Recetas/registro.php on line 52
El Usuario toni se Registro Correctamente
- $this->nombre has a not null value (checked)
- Database its empty, so there should be never results.
- The problem it's that the script goes on and pretends that user has been registered, even shows the name! and there is not an update on database..
I just can't see the problem.. can you?
thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
删除“now()”周围的引号,否则您将作为字符串而不是 MySQL 时间戳插入
remove the quotes from around 'now()' else you are inserting as a string instead of MySQL timestamp
在这里使用串联:
use concatenation here :
PHP 手册说:
如果您没有“当前活动数据库”,那么您的 mysql_* 调用将会失败。在调用中提供 MySQL 连接链接标识符始终是最佳实践。
你在哪里调用 mysql_connect ?
The PHP manual says:
If you do not have a "currently active database" then your mysql_* calls will fail. It's always best practice to supply the MySQL connection link identifier with your calls.
Where are you calling mysql_connect?
好吧,非常感谢你帮助我,
似乎有一个不同的错误(带有属性名称,典型......)但仍然值得,因为发现了这些错误..
如果有人需要它,类代码: (调整您的属性)
再次感谢!
Well, thank you very much for helping me,
it seems that there was a different error (with a atribute name, tipical...) but stills worthy because found out about those errors..
If some one needs it, the class code: (adapt your atributes)
Thanks again!
试试这个吧;
我在您的代码中没有看到任何 mysql_fetch_array() 语句。
Try this one instead;
And I don't see any mysql_fetch_array() statement in your code.