Foros del Web » Programando para Internet » PHP »

Ayuda con este error!

Estas en el tema de Ayuda con este error! en el foro de PHP en Foros del Web. Alguien me ayuda con este codigo? Me da el siguiente error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\OH\usuarios\register.php on ...
  #1 (permalink)  
Antiguo 05/12/2008, 09:50
 
Fecha de Ingreso: noviembre-2008
Mensajes: 259
Antigüedad: 15 años, 4 meses
Puntos: 1
Ayuda con este error!

Alguien me ayuda con este codigo? Me da el siguiente error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\OH\usuarios\register.php on line 54

Muchas gracias!

<?php

session_start(); //allows session
include "config.php";
echo "<center>";

//checks if there trying to verify there account
if(isset($_GET['verify']))
{
//gets the code and makes it safe
$code = addslashes($_GET['code']);
//gets the code from the database
$getcode=mysql_query("SELECT * FROM verificar WHERE code = '$code'");
//counts the number of rows
$getcode = mysql_num_rows($getcode);
//if the ammount of rows is 0 the code does not exist
if($getcode == 0)
{
echo "Invalid verification code!";
}
//or if the code does exist we will activiate there account
else{
//get the data from the database
$getcode=mysql_query("SELECT * FROM verificar WHERE code = '$code'");
//fetchs the data from the db
$dat = mysql_fetch_array($getcode);
//sets the users user level to 2 which means they can now use there account
$update = mysql_query("UPDATE usuarios SET nivel = '2' WHERE usuario = '".$dat[usuario]."'") or die(mysql_error());
//deletes the code as there is no use of it now
$delete = mysql_query("DELETE FROM verificar WHERE code = '$code'");
//says thanks and your account is ready for use
echo "Gracias, su cuenta ha sido verificada";
}
}else
//if we have posted the register for we will register this user
if(isset($_GET['register'])) {
//check to see if any fields were left blank
if((!$_POST[usuario]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST[email])) {
echo "Debe completar todas las opciones";
}
else
{
//posts all the data from the register form
$usuario = $_POST[usuario];
$password = $_POST[password];
$cpassword = $_POST[cpassword];
$email = $_POST[email];
//check see if the 2 passwords are the same
if($password == $cpassword)
{
//encrypts the password 8 times
$password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($password))))) )));
$cname = mysql_query("SELECT usuario FROM usuarios WHERE usuario = '$usuario'");
$cname= mysql_num_rows($cname);
//checks to see if the username or email allready exist
if($cname>=1) {
echo "El nombre de usuario ya existe";
}
else
{
//gets rid of bad stuff from there username and email
$usuario = addslashes(htmlspecialchars($usuario));
$email = addslashes(htmlspecialchars($email));

if($semail == "1") { // $email set as 1 means email activation is active
//adds them to the db
$adduser = mysql_query("INSERT INTO usuarios (usuario, password, email) VALUES('$usuario','$password','$email')");
//posible letters for the verification code
$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789";
//shuffles the letters around to create a 16 long code
$code = substr(str_shuffle($alphanum), 0, 16);
//adds there code along with there user name to the db
$addcode = mysql_query("INSERT INTO verificar (usuario, code) VALUES('$usuario','$code')");
//don't edit this, this is the link for there activication
$link = "http://$host$self?verify&code=$code";
//sends the email to the person
mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename.
Please copy the below link into you address bar,

$link", "From: Site Verification");
//message sent now lets tell them to check there email
echo "Ha sido registrado<br><br>Compruebe su email para activar la cuenta";
}
else
{
//no need for email activation
$adduser = mysql_query("INSERT INTO usuarios (usuario, password, email, nivel) VALUES('$usuario','$password','$email','2')");
echo "Ha sido registrado<br><br>Puede entrar en su cuenta";
}
}
}
else
{
echo "Su password no coincide con su password confirmado";
}
}
}
else
{
//none of the above so lets show the register form
echo "<form action='register.php?register' method='post'>
<table width='350'>
<tr>
<td width='150'>USUARIO:</td>
<td width='200'><input type='text' name='usuario' size='30' maxlength='25'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' size='30' maxlength='25'></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type='password' name='cpassword' size='30' maxlength='25'></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' name='email' size='30' maxlength='55'></td>
</tr>
<tr>
<td colspan='2'><center><input type='submit' value='Register'></center></td>
</tr>
</table>
</form>";
}
echo "<center>";
?>
  #2 (permalink)  
Antiguo 05/12/2008, 10:44
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Ayuda con este error!

Imprime el valor de mysql_error() este te indica si hay un problema con tu consulta.

Saludos.
  #3 (permalink)  
Antiguo 05/12/2008, 11:08
Avatar de danielrivas  
Fecha de Ingreso: noviembre-2007
Ubicación: Preprocessing
Mensajes: 275
Antigüedad: 16 años, 5 meses
Puntos: 6
Respuesta: Ayuda con este error!

$cname = mysql_query("SELECT usuario FROM usuarios WHERE usuario = '$usuario'");
$cname= mysql_num_rows($cname);


Aqui esta el error...has vuelto a definir la variable $cname al hacer el mysql_num_rows...

deberias hacer algo asi:

$rows=mysql_num_rows($cname);
  #4 (permalink)  
Antiguo 06/12/2008, 12:36
 
Fecha de Ingreso: noviembre-2008
Mensajes: 259
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: Ayuda con este error!

No funcionó. Sigue dandome el mismo error.

Que puede ser?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:02.