Foros del Web » Programando para Internet » PHP »

no entiendo el error

Estas en el tema de no entiendo el error en el foro de PHP en Foros del Web. hola chicos, pues eso tengo hecho un par de formularios de registros , pero tengo un problema , los son son casi igueles, pero en ...
  #1 (permalink)  
Antiguo 08/01/2012, 07:30
 
Fecha de Ingreso: diciembre-2010
Ubicación: tenerife
Mensajes: 60
Antigüedad: 13 años, 3 meses
Puntos: 0
no entiendo el error

hola chicos, pues eso tengo hecho un par de formularios de registros , pero tengo un problema , los son son casi igueles, pero en uno me sale esto 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 '±a, avatar, nombre) VALUES (5, 'carlitos', 'saratoga', 'nada', 'manolito')' at line 1 , este es el codigo
Código PHP:
Ver original
  1. <?php require_once('Connections/prueba.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 usuarios (id_usuario, usuario, contraseña, avatar, nombre) VALUES (%s, %s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['id_usuario'], "int"),
  42.                        GetSQLValueString($_POST['usuario'], "text"),
  43.                        GetSQLValueString($_POST['contraseña'], "text"),
  44.                        GetSQLValueString($_POST['avatar'], "text"),
  45.                        GetSQLValueString($_POST['nombre'], "text"));
  46.  
  47.   mysql_select_db($database_prueba, $prueba);
  48.   $Result1 = mysql_query($insertSQL, $prueba) or die(mysql_error());
  49.  
  50.   $insertGoTo = "prueba.php";
  51.   if (isset($_SERVER['QUERY_STRING'])) {
  52.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  53.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  54.   }
  55.   header(sprintf("Location: %s", $insertGoTo));
  56. }
  57.  
  58. mysql_select_db($database_prueba, $prueba);
  59. $query_priemera_prueba = "SELECT * FROM usuarios";
  60. $priemera_prueba = mysql_query($query_priemera_prueba, $prueba) or die(mysql_error());
  61. $row_priemera_prueba = mysql_fetch_assoc($priemera_prueba);
  62. $totalRows_priemera_prueba = mysql_num_rows($priemera_prueba);
  63. ?>
  64.  
  65. <body>
  66. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  67.   <table width="354" align="center" bgcolor="#CC33CC">
  68.     <tr valign="baseline">
  69.       <td nowrap="nowrap" align="right">Id_usuario:</td>
  70.       <td><input type="text" name="id_usuario" value="" size="32" /></td>
  71.     </tr>
  72.     <tr valign="baseline">
  73.       <td nowrap="nowrap" align="right">Usuario:</td>
  74.       <td><input type="text" name="usuario" value="" size="32" /></td>
  75.     </tr>
  76.     <tr valign="baseline">
  77.       <td height="25" align="right" nowrap="nowrap">Clave:</td>
  78.       <td><input type="text" name="contraseña" value="" size="32" /></td>
  79.     </tr>
  80.     <tr valign="baseline">
  81.       <td nowrap="nowrap" align="right">Avatar:</td>
  82.       <td><input type="text" name="avatar" value="" size="32" /></td>
  83.     </tr>
  84.     <tr valign="baseline">
  85.       <td nowrap="nowrap" align="right">Nombre:</td>
  86.       <td><input type="text" name="nombre" value="" size="32" /></td>
  87.     </tr>
  88.     <tr valign="baseline">
  89.       <td nowrap="nowrap" align="right">&nbsp;</td>
  90.       <td><input type="submit" value="Insertar registro" /></td>
  91.     </tr>
  92.   </table>
  93.   <input type="hidden" name="MM_insert" value="form1" />
  94. </form>
  95. <p>&nbsp;</p>
  96. </body>
  97. </html>
  98. <?php
  99. mysql_free_result($priemera_prueba);
  100. ?>

pero en este no me da error
Código PHP:
Ver original
  1. <?php require_once('Connections/prueba.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 usuarios (id_usuario, usuario, clave, avatar, nombre) VALUES (%s, %s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['id_usuario'], "int"),
  42.                        GetSQLValueString($_POST['usuario'], "text"),
  43.                        GetSQLValueString($_POST['clave'], "text"),
  44.                        GetSQLValueString($_POST['avatar'], "text"),
  45.                        GetSQLValueString($_POST['nombre'], "text"));
  46.  
  47.   mysql_select_db($database_prueba, $prueba);
  48.   $Result1 = mysql_query($insertSQL, $prueba) or die(mysql_error());
  49.  
  50.   $insertGoTo = "prueba.php";
  51.   if (isset($_SERVER['QUERY_STRING'])) {
  52.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  53.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  54.   }
  55.   header(sprintf("Location: %s", $insertGoTo));
  56. }
  57.  
  58. mysql_select_db($database_prueba, $prueba);
  59. $query_priemera_prueba = "SELECT * FROM usuarios";
  60. $priemera_prueba = mysql_query($query_priemera_prueba, $prueba) or die(mysql_error());
  61. $row_priemera_prueba = mysql_fetch_assoc($priemera_prueba);
  62. $totalRows_priemera_prueba = mysql_num_rows($priemera_prueba);
  63. ?>
  64.  
  65. <body>
  66. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  67.   <table width="354" align="center" bgcolor="#CC33CC">
  68.     <tr valign="baseline">
  69.       <td nowrap="nowrap" align="right">Id_usuario:</td>
  70.       <td><input type="text" name="id_usuario" value="" size="32" /></td>
  71.     </tr>
  72.     <tr valign="baseline">
  73.       <td nowrap="nowrap" align="right">Usuario:</td>
  74.       <td><input type="text" name="usuario" value="" size="32" /></td>
  75.     </tr>
  76.     <tr valign="baseline">
  77.       <td height="25" align="right" nowrap="nowrap">Clave:</td>
  78.       <td><input type="text" name="clave" value="" size="32" /></td>
  79.     </tr>
  80.     <tr valign="baseline">
  81.       <td nowrap="nowrap" align="right">Avatar:</td>
  82.       <td><input type="text" name="avatar" value="" size="32" /></td>
  83.     </tr>
  84.     <tr valign="baseline">
  85.       <td nowrap="nowrap" align="right">Nombre:</td>
  86.       <td><input type="text" name="nombre" value="" size="32" /></td>
  87.     </tr>
  88.     <tr valign="baseline">
  89.       <td nowrap="nowrap" align="right">&nbsp;</td>
  90.       <td><input type="submit" value="Insertar registro" /></td>
  91.     </tr>
  92.   </table>
  93.   <input type="hidden" name="MM_insert" value="form1" />
  94. </form>
  95. <p>&nbsp;</p>
  96. </body>
  97. </html>
  98. <?php
  99. mysql_free_result($priemera_prueba);
  100. ?>

quizas el error sea lo de la contraseña, con eso de q lleva la ñ , la base de datos tiene cotejamiento ascii_general_ci , aunque tambien probe htf8 y me da el mismo error
  #2 (permalink)  
Antiguo 08/01/2012, 07:46
3nr1c
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: no entiendo el error

Me parece que el problema es la ñ como bien dices.... Prueba a poner contrasena a ver que tal

Saludos!
  #3 (permalink)  
Antiguo 08/01/2012, 08:29
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: no entiendo el error

Por un lado, los DBMS en general y MySQL en particular no se llevan bien con los caracteres extendidos, por lo que no es buena práctica usar eñes, vocales acentuadas o letras especificas de cualquier otro idioma, y que no esté entre las 27 que el inglés reconoce.
También debes evitar nombres que sean palabras reservadas del SQL, por lo que no puedes usar cosas como STATUS, DATA, FIELD, PASSWORD, y una larga lista, que puedes consultar en el capítulo respectivo del manual de referencia.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #4 (permalink)  
Antiguo 08/01/2012, 11:24
 
Fecha de Ingreso: diciembre-2010
Ubicación: tenerife
Mensajes: 60
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: no entiendo el error

pues si, era la ñ, asi q la quite del php , y ya esta , le di un id que en vez d llamarse contraseña se llama clave , gracias

Etiquetas: formulario, html, mysql, registro, sql, usuarios
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 12:42.