我正在尝试定义一个用户注册类,这是我现在拥有的功能
<?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():提供的参数不是有效的 MySQL 结果资源,位于 /home/piscolab/public_html/keepyourlinks.com/Recetas/registro.php 第 52 行 El Usuario toni se Registro Correctamente
- $this->nombre 有一个非空值(选中)
- 数据库是空的,所以应该永远不会有结果。
- 问题是脚本继续并假装用户已注册,甚至显示名称!并且数据库没有更新..
我只是看不到问题..你可以吗?
谢谢你!