Foros del Web » Programando para Internet » PHP »

ERROR: SQL syntax;

Estas en el tema de ERROR: SQL syntax; en el foro de PHP en Foros del Web. saludos estoy desarrollando un panel y me sale este error You have an error in your SQL syntax; check the manual that corresponds to your ...
  #1 (permalink)  
Antiguo 14/02/2008, 11:01
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
ERROR: SQL syntax;

saludos estoy desarrollando un panel y me sale este 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 ')' at line 1

Agradeceria una manito..
el codigo se los pongo a parte pues son muchos caracteres
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 14/02/2008, 11:04
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: ERROR: SQL syntax;

y el codigo???
__________________
Degiovanni Emilio
developtus.com
  #3 (permalink)  
Antiguo 14/02/2008, 11:05
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: SQL syntax;

Código PHP:
<?php require_once('../Connections/connect.php'); ?>
<?php
include_once("fckeditor/fckeditor.php") ;
?>

<?php

function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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")) {

$ediciondir'../images2/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['imagen']['tmp_name'], $uploaddir $_FILES['imagen']['name']);    
$filename $_FILES['imagen']['name'];

$ediciondir'../ficha/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['ficha']['tmp_name'], $uploaddir $_FILES['ficha']['name']);    
$filename2 $_FILES['ficha']['name'];


$insertSQL sprintf("INSERT INTO producto (Id_categoria, Id_marca, nombre, codigo, uso, descripcion, tipo, imagen, ficha, status) VALUES (%s, %s, %s, %s %s, %s, %s, %s, %s, %s, %s,)",
                       
GetSQLValueString($_POST['Id_categoria'], "int"),
                       
GetSQLValueString($_POST['Id_marca'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['codigo'], "text"),
                       
GetSQLValueString($_POST['uso'], "text"),
                       
GetSQLValueString($_POST['descripcion'], "text"),
                       
GetSQLValueString($_POST['tipo'], "text"),
                       
GetSQLValueString($filename"text"),
                       
GetSQLValueString($filename2"text"),
                       
GetSQLValueString($_POST['status'], "text"));

  
mysql_select_db($database_connect$connect);
  
$Result1 mysql_query($insertSQL$connect) or die(mysql_error());

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

mysql_select_db($database_connect$connect);
$query_Recordset1 "SELECT * FROM categoria";
$Recordset1 mysql_query($query_Recordset1$connect) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_connect$connect);
$query_Recordset2 "SELECT * FROM marca";
$Recordset2 mysql_query($query_Recordset2$connect) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);

?>



<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">

    <td><TABLE width=500 border=0 align="center" cellPadding=0 cellSpacing=0 bordercolor="#FF0000" id=table2>
      <TBODY>
        <TR>
          <TD width="8" vAlign=top ></TD>
          <TD width=498 align="center" vAlign=middle class="nucomplet"><form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1" onSubmit="MM_validateForm('descripcion','','R');return document.MM_returnValue">
              <table width="414" align="center">
                <tr valign="baseline">
                  <td width="96" align="right" valign="middle" nowrap class="textoINDEX"><div align="left">Categoria: </div></td>
                  <td width="306" valign="middle" class="textoINDEX"><div align="left">
                      <select name="Id_categoria" class="todopanel" id="Id_categoria">
                        <?php
do {  
?>
                        <option value="<?php echo $row_Recordset1['Id_categoria']?>"><?php echo $row_Recordset1['nombre']?></option>
                        <?php
} while ($row_Recordset1 mysql_fetch_assoc($Recordset1));
  
$rows mysql_num_rows($Recordset1);
  if(
$rows 0) {
      
mysql_data_seek($Recordset10);
      
$row_Recordset1 mysql_fetch_assoc($Recordset1);
  }
?>
                      </select>
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" nowrap class="textoINDEX"><div align="left">Marca</div></td>
                  <td align="left" valign="middle" class="textoINDEX"><div align="left">
                      <select name="Id_marca" class="todopanel" id="Id_marca">
                        <?php
do {  
?>
                        <option value="<?php echo $row_Recordset2['Id_marca']?>"><?php echo $row_Recordset2['nombre']?></option>
                        <?php
} while ($row_Recordset2 mysql_fetch_assoc($Recordset2));
  
$rows mysql_num_rows($Recordset2);
  if(
$rows 0) {
      
mysql_data_seek($Recordset20);
      
$row_Recordset2 mysql_fetch_assoc($Recordset2);
  }
?>
                      </select>
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" nowrap class="textoINDEX"><div align="left">Nombre:</div></td>
                  <td valign="middle" class="textoINDEX"><div align="left">
                      <input name="nombre" type="text" class="todopanel">
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" nowrap class="textoINDEX"><div align="left">Codigo</div></td>
                  <td align="left" valign="middle" class="textoINDEX"><input type="text" name="codigo" id="codigo">
                      </label></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" class="textoINDEX"><div align="left">Uso</div></td>
                  <td align="left" valign="middle" class="textoINDEX"><input type="text" name="uso" id="uso"></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" class="textoINDEX"><div align="left">Descripci&oacute;n</div></td>
                  <td align="left" valign="middle" class="textoINDEX"><?php
$oFCKeditor 
= new FCKeditor('descripcion') ;
$oFCKeditor->BasePath 'fckeditor/' ;
$oFCKeditor->Value '<p></p>' ;
$oFCKeditor->Create() ;
?></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" nowrap class="textoINDEX"><div align="left">
                    <p>Tipo</p>
                    </div></td>
                  <td valign="middle" class="textoINDEX"><div align="left">
                    <input type="text" name="tipo" id="tipo">
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" class="textoINDEX"><div align="left">Ficha</div></td>
                  <td valign="middle" class="textoINDEX"><div align="left">
                      <input name="ficha" type="file" class="todopanel" id="ficha"  enctype="multipart/form-data">
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" class="textoINDEX"><div align="left">Imagen:</div></td>
                  <td valign="middle" class="textoINDEX"><div align="left">
                      <input name="imagen" type="file" class="todopanel"  enctype="multipart/form-data">
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td align="left" valign="middle" class="textoINDEX">Status</td>
                  <td valign="middle" class="textoINDEX"><label>
                    <select name="status" id="status">
                      <option>0</option>
                      <option value="Impresi&oacute;n una cara">1</option>
                      <option value="Impresi&oacute;n doble cara">2</option>
                      <option value="Laminado">3</option>
                                                                                </select>
                  </label></td>
                </tr>
                <tr valign="baseline">
                  <td align="right" valign="middle" class="Estilo6"><div align="left">
                      <input type="hidden" name="MM_insert" value="form1">
                  </div></td>
                  <td valign="middle"><div align="left"></div></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap align="right">&nbsp;</td>
                  <td><div align="left">
                      <input name="submit" type="submit" class="todopanel" value="Insertar registro">
                  </div></td>
                </tr>
              </table>
          </form></TD>
          <TD width=13 vAlign=top>&nbsp;</TD>
        </TR>
      </TBODY>
    </TABLE></td>
  </tr>
  <tr>
    <td><img src="images/footer.jpg" width="500" height="8"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>

<?php
mysql_free_result
($Recordset1);
mysql_free_result($Recordset2);
?>
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #4 (permalink)  
Antiguo 14/02/2008, 11:08
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: ERROR: SQL syntax;

tenes un %s, de mas

$insertSQL = sprintf("INSERT INTO producto (Id_categoria, Id_marca, nombre, codigo, uso, descripcion, tipo, imagen, ficha, status) VALUES (%s, %s, %s, %s %s, %s, %s, %s, %s, %s)",

ahora si
__________________
Degiovanni Emilio
developtus.com
  #5 (permalink)  
Antiguo 14/02/2008, 11:13
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: SQL syntax;

Cita:
Iniciado por emiliodeg Ver Mensaje
tenes un %s, de mas

$insertSQL = sprintf("INSERT INTO producto (Id_categoria, Id_marca, nombre, codigo, uso, descripcion, tipo, imagen, ficha, status) VALUES (%s, %s, %s, %s %s, %s, %s, %s, %s, %s)",

ahora si

me dice ahora esto
Column count doesn't match value count at row 1
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #6 (permalink)  
Antiguo 14/02/2008, 11:18
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: ERROR: SQL syntax;

en q linea??? fijate donde te dice y marcamela por q el spintf esta bien
__________________
Degiovanni Emilio
developtus.com
  #7 (permalink)  
Antiguo 14/02/2008, 11:21
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: SQL syntax;

ok eso lo acomode... fijate q en la cadena falta una , (%s, %s, %s, %s %s, %s, %s, %s, %s, %s)",
en el 4to...
y ya envia....
solo q cuando inserta y dice esto
Warning: Cannot modify header information - headers already sent by (output started at /home/cersolve/public_html/sitepanel/adm_pro2.php:6) in /home/cersolve/public_html/sitepanel/adm_pro2.php on line 73
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #8 (permalink)  
Antiguo 14/02/2008, 11:33
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: ERROR: SQL syntax;

Eso te sale porque ya enviaste contenido en la linea 6, de tu archivo adm_pro2.php, por lo que ya no puedes enviar las cabeceras en la linea 73.

Saludos.
  #9 (permalink)  
Antiguo 14/02/2008, 11:38
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: SQL syntax;

aja... pero si en la linea 6
solo tengo esto
<?php

seguido mas abajo d esto

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

entonces... en la 73 viene esto
Código PHP:
$insertGoTo "list_prod.php"
  if (isset(
$_SERVER['QUERY_STRING'])) { 
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?"
    
$insertGoTo .= $_SERVER['QUERY_STRING']; 
  } 
 
header(sprintf("Location: %s"$insertGoTo)); 

__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #10 (permalink)  
Antiguo 14/02/2008, 11:45
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: ERROR: SQL syntax;

Antes de la linea 6 que tienes?

Saludos.
  #11 (permalink)  
Antiguo 14/02/2008, 11:57
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: SQL syntax;

Código PHP:
<?php require_once('../Connections/connect.php'); ?>
<?php
include_once("fckeditor/fckeditor.php") ;
?>
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #12 (permalink)  
Antiguo 14/02/2008, 12:42
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: ERROR: SQL syntax;

Debes de tener en algun lado un espacio en blanco o codigo html y es por eso que no te deja enviar las cabeceras.

Saludos.
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 07:55.