Foros del Web » Programando para Internet » PHP »

Sistema de registro en PHP.

Estas en el tema de Sistema de registro en PHP. en el foro de PHP en Foros del Web. Llevo unos cuantos días intentando hacer un sistema de registros php y mysql para mi web pero me encuentro con el siguiente error: Cita: You ...
  #1 (permalink)  
Antiguo 03/10/2013, 06:28
 
Fecha de Ingreso: octubre-2013
Mensajes: 30
Antigüedad: 10 años, 6 meses
Puntos: 3
Pregunta Sistema de registro en PHP.

Llevo unos cuantos días intentando hacer un sistema de registros php y mysql para mi web pero me encuentro con el siguiente error:
Cita:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-mail, password, rpassword) VALUES ('usuario', '[email protected]', 'contraseña' at line 1
Me indica que el fallo está en la linea 1 de este código:


Código PHP:
Ver original
  1. <?php require_once('Connections/ConexionP.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.   $insertSQL = sprintf("INSERT INTO registro (nombre, e-mail, password, rpassword) VALUES (%s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['nombre'], "text"),
  42.                        GetSQLValueString($_POST['email'], "text"),
  43.                        GetSQLValueString($_POST['password'], "text"),
  44.                        GetSQLValueString($_POST['rpassword'], "text"));
  45.  
  46.   mysql_select_db($database_ConexionP, $ConexionP);
  47.   $Result1 = mysql_query($insertSQL, $ConexionP) or die(mysql_error());
  48.  
  49.   $insertGoTo = "registro.php";
  50.   if (isset($_SERVER['QUERY_STRING'])) {
  51.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  52.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  53.   }
  54.   header(sprintf("Location: %s", $insertGoTo));
  55. }
  56. ?>
  57. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  58. <html xmlns="http://www.w3.org/1999/xhtml">
  59. <head>
  60. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  61. <title>Documento sin título</title>
  62. </head>
  63.  
  64. <body>
  65. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  66.   <table align="center">
  67.     <tr valign="baseline">
  68.       <td nowrap="nowrap" align="right">*Nombre:</td>
  69.       <td><input type="text" name="nombre" value="" size="32" required="required" /></td>
  70.     </tr>
  71.     <tr valign="baseline">
  72.       <td nowrap="nowrap" align="right">*E-mail:</td>
  73.       <td><input type="email" name="email" value="" size="32" required="required" /></td>
  74.     </tr>
  75.     <tr valign="baseline">
  76.       <td nowrap="nowrap" align="right">*Contraseña:</td>
  77.       <td><input type="password" name="password" value="" size="32" required="required" /></td>
  78.     </tr>
  79.     <tr valign="baseline">
  80.       <td nowrap="nowrap" align="right">*Repetir Contraseña:</td>
  81.       <td><input type="password" name="rpassword" value="" size="32" required="required" /></td>
  82.     </tr>
  83.     <tr valign="baseline">
  84.       <td nowrap="nowrap" align="right">&nbsp;</td>
  85.       <td><input type="submit" value="Registrarse" /></td>
  86.     </tr>
  87.   </table>
  88.   <input type="hidden" name="MM_insert" value="form1" />
  89. </form>
  90. <p>&nbsp;</p>
  91. </body>
  92. </html>

Pero no veo el error, aunque dice que es un error de sintaxis yo no veo nada mal, también me comentaron que las nuevas versiones de los servidores están lanzando errores como este, pero la verdad no sé como abarcarlo y agradecería vuetra ayuda os dejo también el codigo del archivo 'Connections/ConexionP.php'
aunque no creo que tenga nada que ver:

Código PHP:
Ver original
  1. <?php
  2. # FileName="Connection_php_mysql.htm"
  3. # Type="MYSQL"
  4. # HTTP="true"
  5. $hostname_ConexionP = "localhost";
  6. $database_ConexionP = "web";
  7. $username_ConexionP = "root";
  8. $password_ConexionP = "1234";
  9. $ConexionP = mysql_pconnect($hostname_ConexionP, $username_ConexionP, $password_ConexionP) or trigger_error(mysql_error(),E_USER_ERROR);
  10. ?>
  #2 (permalink)  
Antiguo 03/10/2013, 06:44
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Sistema de registro en PHP.

Código PHP:
Ver original
  1. $insertSQL = sprintf("INSERT INTO registro (´nombre´, ´e-mail´, ´password´, ´rpassword´) VALUES (%s, %s, %s, %s)",
  2.                        GetSQLValueString($_POST['nombre'], "text"),
  3.                        GetSQLValueString($_POST['email'], "text"),
  4.                        GetSQLValueString($_POST['password'], "text"),
  5.                        GetSQLValueString($_POST['rpassword'], "text"));

Pon delimitadores en los nombres de los campos de la linea 40.

Tienes dos problemas usas "-" en e-mail, un simbolo raro, y password una palabra reservada.

Si sigue con el error yo quitaria ese guion.... email es facil de leer igual que e-mail
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.
  #3 (permalink)  
Antiguo 03/10/2013, 07:05
 
Fecha de Ingreso: octubre-2013
Mensajes: 30
Antigüedad: 10 años, 6 meses
Puntos: 3
Respuesta: Sistema de registro en PHP.

He quitado el - de email de la base de datos y el código, además de cambiar la palabra password por pw. También puse delimitadores en la linea 40 y nada. Por cierto como ya imaginarás el error se produce al clickar en el 'submit' tras introducir los datos. Te dejo el código modificado a ver si ves algo raro:

Código PHP:
<?php require_once('Connections/ConexionP.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO registro ('nombre', 'email', 'pw', 'rpw') VALUES (%s, %s, %s, %s)",
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['pw'], "text"),
                       
GetSQLValueString($_POST['rpw'], "text"));

  
mysql_select_db($database_ConexionP$ConexionP);
  
$Result1 mysql_query($insertSQL$ConexionP) or die(mysql_error());

  
$insertGoTo "registro.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Usuario:</td>
      <td><input type="text" name="nombre" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email:</td>
      <td><input type="email" name="email" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Contraseña:</td>
      <td><input type="password" name="pw" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Repetir Contraseña:</td>
      <td><input type="password" name="rpw" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
  #4 (permalink)  
Antiguo 04/10/2013, 01:55
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Sistema de registro en PHP.

El delimitador para nombres de campo es `(tilde grave, perdón los puse agudos) no ' (apostrofe), aun que con el cambio de nombre debería funcionar sin delimitadores.

Que error te da ahora?
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.

Etiquetas: dudas, registro, registros, sistema, sistemas
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 09:13.