Foros del Web » Programando para Internet » PHP »

Error de Mysql y PHP

Estas en el tema de Error de Mysql y PHP en el foro de PHP en Foros del Web. Bueno, mi problema esta en que no soy muy experimentado en el tema de programacion con PHP y Mysql, estoy aprendiendo a los ponchasos, ja, ...
  #1 (permalink)  
Antiguo 01/03/2012, 16:08
 
Fecha de Ingreso: agosto-2010
Mensajes: 3
Antigüedad: 13 años, 8 meses
Puntos: 0
Error de Mysql y PHP

Bueno, mi problema esta en que no soy muy experimentado en el tema de programacion con PHP y Mysql, estoy aprendiendo a los ponchasos, ja, siempre fui creyente que se aprende mejor equivocandose. Bueno resulta que necesito hacer un formulario de envio de datos de usuario, lo estoy haciendo en dreamweaver con PHP y Mysql, tengo todo hecho, la conoexion a la base de datos, y el form para enviarlo, pero al momento de dar click en el boton de envio, me salta el siguiente error.

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) VALUES (NULL, 'asdasd', 'asd', NULL, 0, NULL, NULL, NULL)' at line 1

doy por sentado que el error viene dado por los valores que le estoy dando a los campos pero bue, como dije no se donde modificar el codigo. Aca abajo ingreso el codigo que me genera la base de datos en PhpMyadmin

================================================== ========


<?php require_once('Connections/Registro.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"] == "form2")) {
$insertSQL = sprintf("INSERT INTO regstrousuarios (IdUsuario, Nombre, Apellido, Direccion, Telefono, Email, Usuario, Contraseña) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['IdUsuario'], "int"),
GetSQLValueString($_POST['Nombre'], "text"),
GetSQLValueString($_POST['Apellido'], "text"),
GetSQLValueString($_POST['Direccion'], "text"),
GetSQLValueString($_POST['Telefono'], "int"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['Usuario'], "text"),
GetSQLValueString($_POST['Contrasea'], "text"));

mysql_select_db($database_Registro, $Registro);
$Result1 = mysql_query($insertSQL, $Registro) or die(mysql_error());

$insertGoTo = "reg_exitoso.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>

================================================== =======

aca tambien dejjo el link de una pagina con la cual me guie para hacer la conexion y la creacion del formulario para ingresar los datos....

http://cyberexplorador.wordpress.com/2010/03/27/consultar-insertar-y-modificar-registros-de-una-base-de-datos-de-mysql-con-php-sin-programar-nada/


================================================== =======

saludos, espero puedan ayudarme.
  #2 (permalink)  
Antiguo 01/03/2012, 16:51
 
Fecha de Ingreso: septiembre-2011
Ubicación: DF
Mensajes: 26
Antigüedad: 12 años, 6 meses
Puntos: 6
Respuesta: Error de Mysql y PHP

Hola q tal,

el error que mencionas debe ser por la ñ en el insert INSERT INTO regstrousuarios (IdUsuario, N... , Contraseña) values (....), puedes cambiarlo pon una "n" y por consiguiente en tu base de datos el campo Contraseña cámbialo por Contrasena


Saludos
  #3 (permalink)  
Antiguo 02/03/2012, 06:35
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Error de Mysql y PHP

Haz echo de la sentencia y pruébala en tu cliente mysql:


Código PHP:
Ver original
  1. echo $insertSQL = sprintf("INSERT INTO regstrousuarios (IdUsuario, Nombre, Apellido, Direccion, Telefono, Email, Usuario, Contraseña) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
  2. GetSQLValueString($_POST['IdUsuario'], "int"),
  3. GetSQLValueString($_POST['Nombre'], "text"),
  4. GetSQLValueString($_POST['Apellido'], "text"),
  5. GetSQLValueString($_POST['Direccion'], "text"),
  6. GetSQLValueString($_POST['Telefono'], "int"),
  7. GetSQLValueString($_POST['Email'], "text"),
  8. GetSQLValueString($_POST['Usuario'], "text"),
  9. GetSQLValueString($_POST['Contrasea'], "text"));
__________________
Fere libenter homines, id quod volunt, credunt.

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 15:42.