[SOLUCIONADO] Ayuda con el error at line 1

Iniciado por Jonhy87, Diciembre 10, 2012, 09:56:45 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Diciembre 10, 2012, 09:56:45 PM Ultima modificación: Septiembre 26, 2014, 09:33:29 PM por Expermicid
Se Elimino el RegistroYou 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

es el error que me sale cuando quiero borrar un registro:

me canse de buscar por todos lados, si alguien me puede ayudar por favor
este es el código que estoy usando.

Código: php


<HTML>
<style>
.fede{ color:#000000;
font-family:Tahoma, Geneva, sans-serif;
font-size:12px;
font-style:normal;
}
</style>
</HTML>
<?

$HOSTNAME = "localhost";//NOMBRE DE NUESTRO SERVICOR
$USERNAME = "*****"; //NUESTRO USUARIO
$PASSWORD = "****"; //NUESTRA CONTRASEÑA
$DATABASE = "*****";// EL NOMBRE DE LA BAE DE DATOS QUE VAMOS A USAR


// creamos una funcion que se llama conectar, la llamamos por su nombre que es conectar y la pasamos a una variable:
function conectar(){
global $HOSTNAME,$USERNAME,$PASSWORD,$DATABASE;
$idcnx = mysql_connect($HOSTNAME, $USERNAME, $PASSWORD) or DIE(mysql_error());
mysql_select_db($DATABASE, $idcnx);
return $idcnx;
}

// llamo a la funcion conectar y le paso el valor que es verdadero ( que si se conecto) a la variable $conexion 
$conexion = conectar ();
//consulta.
$id=$_GET['id'];
$registros=mysql_query("Select * from stock1 where id=$id",$conexion) or  die("Problemas en el select:".mysql_error());

while ($reg=mysql_fetch_array($registros)){//Devuelve un array de cadenas que corresponde a la fila recuperada, o FALSE si no hay más filas
   
print "<p style='font-size:24px'> ESTA SEGURO DE ELIMINAR EL REGISTRO </p>";
print "<div class='fede'>";
print "<b>Apellido y Nombre: </b>".$reg['nombre']."<br>";
print "<b>DNI:</b>".$reg['dni']."<br>";
print "<b>Telefono: </b>".$reg['telefono']."<br>";
print "<b>Correo: </b>".$reg['email']."<br>";
print "<b>Domicilio: </b>".$reg['domicilio']."<br>";
print "<b>Curso:</b>".$reg['curso']."<br>";
print "<b>Dias     : </b>".$reg['dias']."<br>";
print "<b>Horario     : </b>".$reg['horario']."<br>";
print "-----------------------------------------------------<br>";
print "-----------------------------------------------------<br>";
print "</div>";
}
?>
<form name="form1" method="post" action="eliminar.php">
<table width="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><input name="id" type="hidden" id="id" value="<? echo $_POST['id'];?>"><br>
¿Seguro de querer borrar el registro con id <? echo $_POST['id'];?> ?</td>
</tr>
<tr>
  <td align="right"><input type="submit" name="submit" value="Borrar registro."></td>
</tr>
<tr>
  <td align="center"><a href="listado.php">cancelar</a></td>
</tr>
</table>
</form>
<?

if(isset($_POST['submit'])){

$sql = "DELETE FROM stock1 WHERE id =".$_POST['id']." LIMIT 1";//ELIMINA UN REGISTRO A LA VEZ
$res = mysql_query($sql) or die(mysql_error());
echo"Registro ".$_POST['id']." eliminado.<br><a href='listado.php'>regresar</a>";
mysql_close($conexion);
exit;
}

?>

<a href="eliminar.php?id=<? echo $reg['id'] ?>"> <button > ELIMINAR </button></a>


ese código corresponde al que te tira el error? porque no parece.-


pues es verdad que la linea del error no puede ser la del codigo que estas mostrando...

Pero igual te doy un buen consejo para que puedas arreglar ese error y cualquiera de ese tipo. El error se esta dando porque la sintaxis de la consulta SQL no es valida. Lo que tienes que hacer es que antes de ejecutar una consulta SQL, imprimes en la pantalla la consulta SQL y te daras cuenta cual es el error.

Saludos.
Mi madre me dijo que estoy destinado a ser pobre toda la vida.
Engineering is the art of balancing the benefits and drawbacks of any approach.

Diciembre 12, 2012, 11:19:47 PM #3 Ultima modificación: Diciembre 12, 2012, 11:26:56 PM por fd
Código: php
     
    <HTML>
    <style>
    .fede{ color:#000000;
    font-family:Tahoma, Geneva, sans-serif;
    font-size:12px;
    font-style:normal;
    }
    </style>
    </HTML>
    <?
     
    $HOSTNAME = "localhost";//NOMBRE DE NUESTRO SERVICOR
    $USERNAME = "*****";            //NUESTRO USUARIO
    $PASSWORD = "****";             //NUESTRA CONTRASEÑA
    $DATABASE = "*****";// EL NOMBRE DE LA BAE DE DATOS QUE VAMOS A USAR
     
     
    // creamos una funcion que se llama conectar, la llamamos por su nombre que es conectar y la pasamos a una variable:
    function conectar(){
            global $HOSTNAME,$USERNAME,$PASSWORD,$DATABASE;
            $idcnx = mysql_connect($HOSTNAME, $USERNAME, $PASSWORD) or DIE(mysql_error());
            mysql_select_db($DATABASE, $idcnx);
            return $idcnx;
    }
     
    // llamo a la funcion conectar y le paso el valor que es verdadero ( que si se conecto) a la variable $conexion 
     $conexion = conectar ();
    //consulta.
    $id=(int)$_GET['id'];
    $registros=mysql_query("Select * from stock1 where id=$id",$conexion) or  die("Problemas en el select:".mysql_error());
     
    while ($reg=mysql_fetch_array($registros)){//Devuelve un array de cadenas que corresponde a la fila recuperada, o FALSE si no hay más filas
       
            print "<p style='font-size:24px'> ESTA SEGURO DE ELIMINAR EL REGISTRO </p>";
            print "<div class='fede'>";
            print "<b>Apellido y Nombre: </b>".$reg['nombre']."<br>";
            print "<b>DNI:</b>".$reg['dni']."<br>";
            print "<b>Telefono: </b>".$reg['telefono']."<br>";
            print "<b>Correo: </b>".$reg['email']."<br>";
            print "<b>Domicilio: </b>".$reg['domicilio']."<br>";
            print "<b>Curso:</b>".$reg['curso']."<br>";
            print "<b>Dias     : </b>".$reg['dias']."<br>";
            print "<b>Horario     : </b>".$reg['horario']."<br>";
            print "-----------------------------------------------------<br>";
            print "-----------------------------------------------------<br>";
            print "</div>";
    }
    ?>
    <form name="form1" method="post" action="eliminar.php">
    <table width="400" border="0" cellpadding="0" cellspacing="0">
    <tr>
            <td><input name="id" type="hidden" id="id" value="<? echo $_POST['id'];?>"><br>
                    ¿Seguro de querer borrar el registro con id <? echo $_POST['id'];?> ?</td>
    </tr>
    <tr>
      <td align="right"><input type="submit" name="submit" value="Borrar registro."></td>
    </tr>
    <tr>
      <td align="center"><a href="listado.php">cancelar</a></td>
    </tr>
    </table>
    </form>
    <?
     
    if(isset($_POST['submit'])){

    $id=(int)$_POST['id'];

    $sql = "DELETE FROM stock1 WHERE id=$id LIMIT 1";//ELIMINA UN REGISTRO A LA VEZ
            $res = mysql_query($sql) or die(mysql_error());
            echo "Registro ".$_POST['id']." eliminado.<br><a href='listado.php'>regresar</a>";
            mysql_close($conexion);
            exit;
    }
     
    ?>
     
    <a href="eliminar.php?id=<? echo $reg['id'] ?>"> <button > ELIMINAR </button></a>
     
     


Lee este articulo para evitar SQLi en tus consultas SQL:

No tienes permitido ver los links. Registrarse o Entrar a mi cuenta