Foros del Web » Programando para Internet » PHP »

Fallo de sintaxis sql

Estas en el tema de Fallo de sintaxis sql en el foro de PHP en Foros del Web. Usted tiene un error en la sintaxis SQL, consulte el manual que corresponde a su versión del servidor MySQL para la sintaxis derecho a utilizar ...
  #1 (permalink)  
Antiguo 04/07/2012, 10:52
 
Fecha de Ingreso: julio-2012
Ubicación: valencia
Mensajes: 1
Antigüedad: 11 años, 9 meses
Puntos: 0
Información Fallo de sintaxis sql

Usted tiene un error en la sintaxis SQL, consulte el manual que corresponde a su versión del servidor MySQL para la sintaxis derecho a utilizar cerca de ')' en la línea 1


Hola a todos soy nuevo por este sitio y quisiera un poco de ayuda, porfa.

Este mensaje me sale al hacer un registro a una base de datos desde un formulario, me inserta la imagen a una carpeta especifica peo no me inserta los datos en la base de datos y el código es el siguiente:


<?php require_once('Connections/vtd_bd.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")) {

//Guardar imagen
if(is_uploaded_file($_FILES['file']['tmp_name'])) { // verifica haya sido cargado el archivo
$ruta= 'images/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $ruta);
}

$insertSQL = sprintf("INSERT INTO ac_users (username, password, nombre, apellidos, email, avatar) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['textfield'], "text"),
GetSQLValueString($_POST['textfield2'], "text"),
GetSQLValueString($_POST['textfield3'], "text"),
GetSQLValueString($_POST['textfield4'], "text"),
GetSQLValueString($_POST['textfield5'], "text"),
GetSQLValueString($_POST['file'], $ruta, "text"));

mysql_select_db($database_vtd_bd, $vtd_bd);
$Result1 = mysql_query($insertSQL, $vtd_bd) or die(mysql_error());

$insertGoTo = "index.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=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<table width="600">
<tr>
<td><strong>Nick:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="text" name="textfield" />
</label></td>
</tr>
<tr>
<td><strong>Contrase&ntilde;a:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="password" name="textfield2" />
</label></td>
</tr>
<tr>
<td><strong>Nombre:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="text" name="textfield3" />
</label></td>
</tr>
<tr>
<td><strong>Apellidos:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="text" name="textfield4" />
</label></td>
</tr>
<tr>
<td><strong>E-mail:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="text" name="textfield5" />
</label></td>
</tr>
<tr>
<td><strong>Avatar:</strong></td>
<td>&nbsp;</td>
<td><label>
<input type="file" name="file" />
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><label>
<input type="submit" name="Submit" value="Enviar" />
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
  #2 (permalink)  
Antiguo 04/07/2012, 12:33
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Fallo de sintaxis sql

bienvenido al foro, favor consulte las políticas, use la herramienta highlight para mostrar código

veo que usa funciones para el adecuado filtrado y escapado de los campos a la DB, lo que no veo es si con los string los coloque entre comillas; debe hecer un echo a su SQL para verificar si no existen errores de sintaxis
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #3 (permalink)  
Antiguo 04/07/2012, 12:50
Avatar de patriciomase  
Fecha de Ingreso: abril-2012
Ubicación: Mar del Plata
Mensajes: 323
Antigüedad: 12 años
Puntos: 34
Respuesta: Fallo de sintaxis sql

imprimite esto
Código PHP:
Ver original
  1. $insertSQL = sprintf("INSERT INTO ac_users (username, password, nombre, apellidos, email, avatar) VALUES (%s, %s, %s, %s, %s, %s)",
  2. GetSQLValueString($_POST['textfield'], "text"),
  3. GetSQLValueString($_POST['textfield2'], "text"),
  4. GetSQLValueString($_POST['textfield3'], "text"),
  5. GetSQLValueString($_POST['textfield4'], "text"),
  6. GetSQLValueString($_POST['textfield5'], "text"),
  7. GetSQLValueString($_POST['file'], $ruta, "text"));
por pantalla y fijate que es lo que sale. como dice maycoalvarez debe ser alguna comilla faltante... para mi gusto esta demasiaaaaaado embrollado ese codigo, parece generado por un robot de donde salió?
  #4 (permalink)  
Antiguo 04/07/2012, 13:45
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Fallo de sintaxis sql

en efecto, un código muy grande o saturado es difícil de leer y muchos (como yo) no tenemos tiempo de probarlo línea por línea
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...

Etiquetas: php+bd, sintaxis, bases-de-datos
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 13:28.