Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] You have an error in your SQL syntax;

Estas en el tema de You have an error in your SQL syntax; en el foro de PHP en Foros del Web. He buscado 2 mil errores y no se porque me sale... Cita: You have an error in your SQL syntax; check the manual that corresponds ...
  #1 (permalink)  
Antiguo 16/10/2013, 14:33
 
Fecha de Ingreso: octubre-2013
Mensajes: 42
Antigüedad: 10 años, 6 meses
Puntos: 0
Exclamación You have an error in your SQL syntax;

He buscado 2 mil errores y no se porque me sale...


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 'release 'Usuario', 'Release', 'Autor', 'Autor2', 'Autor3', Autor4, Corto, Corto2' at line 1


Código PHP:
<?php require_once('Connections/Miguel.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 release 'Usuario', 'Release', 'Autor', 'Autor2', 'Autor3', Autor4, Corto, Corto2, Corto3, Corto4, Genero, Archivo VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Usuario'], "text"),
                       
GetSQLValueString($_POST['Release'], "text"),
                       
GetSQLValueString($_POST['Autor'], "text"),
                       
GetSQLValueString($_POST['Autor2'], "text"),
                       
GetSQLValueString($_POST['Autor3'], "text"),
                       
GetSQLValueString($_POST['Autor4'], "text"),
                       
GetSQLValueString($_POST['Corto'], "text"),
                       
GetSQLValueString($_POST['Corto2'], "text"),
                       
GetSQLValueString($_POST['Corto3'], "text"),
                       
GetSQLValueString($_POST['Corto4'], "text"),
                       
GetSQLValueString($_POST['Genero'], "text"),
                       
GetSQLValueString($_FILES['Archivo']['name'], "text"));

  
mysql_select_db($database_Miguel$Miguel);
  
$Result1 mysql_query($insertSQL$Miguel) or die(mysql_error());

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

/* Subir Archivo */
                       
                       
$tamaño $_FILES['Archivo']['size'];
                       
$tipo $_FILES['Archivo']['type'];
                       
$nombre $_FILES['Archivo']['name'];
                       
$temporal $_FILES['Archivo']['tmp_name'];
                       
                       
$sitio "/subidas" $_SESSION['MM_Username'] . $nombre;
                       
                           if(
filesize($temporal) <= 62914560) {
                            
move_uploaded_file($temporal$sitio);
                        }else {
                            echo 
"El archivo es demasiado grande.";    
                        }
                       
                       
/* END Subir Archivo */?>

<!DOCTYPE html>
<html lang="es">
<head>
<link type="text/css" rel="stylesheet" href="css.css">
<meta charset="utf-8" />
<title>Release</title>

<script  type="text/javascript">
         function activar_input() {
             inputs = document.getElementsByTagName('input');
             switch(this.value)
             {

                 case "2":
                     inputs[3].disabled=false;
                     inputs[4].disabled=true;
                     inputs[5].disabled=true;    
                     break;
                 case "3":
                     inputs[3].disabled=false;
                     inputs[4].disabled=false;
                     inputs[5].disabled=true;    
                     break;
                 case "4":
                     inputs[3].disabled=false;
                     inputs[4].disabled=false;
                     inputs[5].disabled=false;        
                     break;
                                 
             }
         }
         
         function manegar_select() {
            selector = document.getElementById("autores");
            selector.addEventListener('change',activar_input,false);
            
        }
        
        
             function activar() {
             inputs = document.getElementsByTagName('input');
             switch(this.value)
             {

                 case "2":
                     inputs[7].disabled=false;
                     inputs[8].disabled=true;
                     inputs[9].disabled=true;    
                     break;
                 case "3":
                     inputs[7].disabled=false;
                     inputs[8].disabled=false;
                     inputs[9].disabled=true;    
                     break;
                 case "4":
                     inputs[7].disabled=false;
                     inputs[8].disabled=false;
                     inputs[9].disabled=false;        
                     break;
                                 
             }
         }
         
         function manegar() {
            selector = document.getElementById("cortos");
            selector.addEventListener('change',activar,false);
            
        }
        
        window.addEventListener('load',manegar_select,false);
        window.addEventListener('load',manegar,false);    
    </script>




</head>

<body>
<form method="POST" name="form1" action="<?php echo $editFormAction?>" enctype="multipart/form-data">
  <table align="center">
  <tr valign="baseline">
      <td nowrap align="right">Usuario:</td>
      <td><p>
        <input type="text" name="Usuario" size="32" value="<?php echo $_SESSION['MM_Username']?>" readonly>
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Release:</td>
      <td><p>
        <input name="Release" type="text" required value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Varios Autores:</td>
      <td><p>
        <label for="autores"></label>
        <select name="autores" id="autores">
          <option value="NO">NO</option>
          <option value="1" id="autores1">1</option>
          <option value="2" id="autores2">2</option>
          <option value="3" id="autores3">3</option>
          <option value="4" id="autores4">4</option>
        </select>
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor:</td>
      <td><p>
        <input type="text" name="Autor" value="" size="32" required>
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor2:</td>
      <td><p>
        <input name="Autor2" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor3:</td>
      <td><p>
        <input name="Autor3" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Autor4:</td>
      <td><p>
        <input name="Autor4" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    
    <tr valign="baseline">
      <td nowrap align="right">Numero de Cortos:</td>
      <td><p>
        <label for="cortos"></label>
        <select name="cortos" id="cortos">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
      </p></td>
    </tr>
    
    <tr valign="baseline">
      <td nowrap align="right">Corto:</td>
      <td><p>
        <input type="text" name="Corto" value="" size="32" required>
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Corto2:</td>
      <td><p>
        <input name="Corto2" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Corto3:</td>
      <td><p>
        <input name="Corto3" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Corto4:</td>
      <td><p>
        <input name="Corto4" type="text" disabled="disabled" value="" size="32">
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Genero:</td>
      <td><p>
        <select name="Genero" required>
          <option value="Accion">Accion</option>
          <option value="Ficcion">Ficcion</option>
          <option value="Aventura">Aventura</option>
          
        </select>
      </p></td>
    <tr>
    <tr valign="baseline">
      <td nowrap align="right">Archivo (60MB Máximo):</td>
      <td><p>
        <input type="file" name="Archivo" value="" size="32" required>
      </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Guardar"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
  #2 (permalink)  
Antiguo 16/10/2013, 14:36
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: You have an error in your SQL syntax;

La sintaxis de SQL que estás utilizando está mal, revisa una referencia.

Cita:
INSERT INTO tabla(a,b,c) VALUES(x,y,z)
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 16/10/2013, 14:43
 
Fecha de Ingreso: octubre-2013
Mensajes: 42
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: You have an error in your SQL syntax;

Cita:
Iniciado por pateketrueke Ver Mensaje
La sintaxis de SQL que estás utilizando está mal, revisa una referencia.
Perdon eso es una prueba que hice, lo puse bien i me dice lo mismo:

Código PHP:
  $insertSQL sprintf("INSERT INTO release(Usuario, Release, Autor, Autor2, Autor3, Autor4, Corto, Corto2, Corto3, Corto4, Genero, Archivo) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Usuario'], "text"),
                       
GetSQLValueString($_POST['Release'], "text"),
                       
GetSQLValueString($_POST['Autor'], "text"),
                       
GetSQLValueString($_POST['Autor2'], "text"),
                       
GetSQLValueString($_POST['Autor3'], "text"),
                       
GetSQLValueString($_POST['Autor4'], "text"),
                       
GetSQLValueString($_POST['Corto'], "text"),
                       
GetSQLValueString($_POST['Corto2'], "text"),
                       
GetSQLValueString($_POST['Corto3'], "text"),
                       
GetSQLValueString($_POST['Corto4'], "text"),
                       
GetSQLValueString($_POST['Genero'], "text"),
                       
GetSQLValueString($_FILES['Archivo']['name'], "text")); 
  #4 (permalink)  
Antiguo 16/10/2013, 14:56
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: You have an error in your SQL syntax;

No es posible que te diga lo mismo, porque no es lo mismo, el usar paréntesis es significativo.

Así que por favor comparte el mensaje de error completo con tu código actual, de otra forma adivinar es imposible.

Ahora, ¿si sabes que SQL tiene palabras reservadas como cualquier otro lenguaje?

Puede que la palabra "release" en si misma sea reservada y por eso no la puedes usar tal cual, ¿ya revisaste una referencia?

PDTA: al final ni siquiera tienes problemas de código PHP, pues el error de sintaxis que obtienes es de SQL y por lo tanto tu problema no corresponde a este foro:
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 16/10/2013, 15:07
Avatar de Cuervoo  
Fecha de Ingreso: octubre-2013
Mensajes: 165
Antigüedad: 10 años, 6 meses
Puntos: 43
Respuesta: You have an error in your SQL syntax;

No te están faltando las comillas en los strings? ('%s')

Código PHP:
Ver original
  1. $insertSQL = sprintf("INSERT INTO release(Usuario, Release, Autor, Autor2, Autor3, Autor4, Corto, Corto2, Corto3, Corto4, Genero, Archivo) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
  2.                        GetSQLValueString($_POST['Usuario'], "text"),
  3.                        GetSQLValueString($_POST['Release'], "text"),
  4.                        GetSQLValueString($_POST['Autor'], "text"),
  5.                        GetSQLValueString($_POST['Autor2'], "text"),
  6.                        GetSQLValueString($_POST['Autor3'], "text"),
  7.                        GetSQLValueString($_POST['Autor4'], "text"),
  8.                        GetSQLValueString($_POST['Corto'], "text"),
  9.                        GetSQLValueString($_POST['Corto2'], "text"),
  10.                        GetSQLValueString($_POST['Corto3'], "text"),
  11.                        GetSQLValueString($_POST['Corto4'], "text"),
  12.                        GetSQLValueString($_POST['Genero'], "text"),
  13.                        GetSQLValueString($_FILES['Archivo']['name'], "text"));
  #6 (permalink)  
Antiguo 16/10/2013, 15:08
Avatar de andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 8 meses
Puntos: 793
Respuesta: You have an error in your SQL syntax;

Encierra Release así:

Código MySQL:
Ver original
  1. `Release`

pero es recomendable que uses otros nombres.

Te dejo la lista de palabras reservadas que debes evitar:

http://dev.mysql.com/doc/refman/5.6/...ved-words.html
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP
  #7 (permalink)  
Antiguo 16/10/2013, 15:20
 
Fecha de Ingreso: octubre-2013
Mensajes: 42
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: You have an error in your SQL syntax;

Cierto! Gracias era que la palabra está reservada, cambie el nombre y listo!

Etiquetas: mysql, syntax
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:12.