Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/01/2012, 07:30
toyeslomao
 
Fecha de Ingreso: diciembre-2010
Ubicación: tenerife
Mensajes: 60
Antigüedad: 13 años, 4 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