Re: [PHP-ES] Duda con mysql_fetch_row
by Satyam other posts by this author
Jun 20 2006 8:40AM messages near this date
Re: [PHP-ES] Duda con mysql_fetch_row
|
Re: [PHP-ES] Duda con mysql_fetch_row
Ye he visto que has solucionado una parte, te falta ponerle un $ delante de
la variable ci, pero lo mas importante es que te falta hacer algo cuando
mysql_query da error.
DeberÃas hacer:
$result=mysql_query($ssql) or die("Error en consulta: <pre> $ssql
</pre> <br />" . mysql_error());
De haber agregado el código indicado, habrÃas detectado el error de
inmediato, con un diagnóstico adecuado y no más tarde cuando usas un $result
que, obviamente, no contiene nada.
Nunca debes dejar de controlar por errores de SQL.
Finalmente, no necesitas guardar el resultado de mysql_fetch_row en
$registro, con esto te basta:
if (mysql_fetch_row($result)) $errstr .= "Ya existe ese registro";
Nota que también use el operador ".=", es más rápido para ejecutar y es más
fácil también para leer.
Satyam
----- Original Message -----
From: "Johnny Sanchez" <johnny@[...].cu>
To: "php" <php-es@[...].net>
Sent: Tuesday, June 20, 2006 6:37 PM
Subject: [PHP-ES] Duda con mysql_fetch_row
Hola listeros, tengo la siguiente duda.
Estoy creando una aplicacion y bueno, para poder entrar los registros debo
comparar que algun campo no se repita, y en este caso he seleccionado el
numero de identidad, entonces para ello use la siguiente sintaxis:
//Chequear el carne de identidad
$ssql=("select ci from datpers wherer ci='".ci."' ");
$result=mysql_query($ssql);
if ($registro = mysql_fetch_row($result)) $errstr = $errstr . "Ya
existe ese registro";
// Concluir
if ($errstr!="") {
echo("$errstr");
mysql_close();
}
la variable $errstr es una variable que puse a cero(0)
entonces cuando ejecuto primeramente me da un error y no me cierra la
coneccion:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result
resource in C:\website\site\infomision\forms\datpers.php on line 459
siendo la linea 459 : if ($registro = mysql_fetch_row($result)) $errstr =
$errstr . "Ya existe ese registro";
Espero me puedan ayudar.
Saludos.
Johnny
--
PHP Spanish Localization Talk Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Johnny Sanchez
Mario Sanchez
Johnny Sanchez
Satyam
Johnny Sanchez
|