Foros del Web » Programando para Internet » PHP »

Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

Estas en el tema de Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS en el foro de PHP en Foros del Web. mi formulario ingreso1 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="css/stylo.css"/> <title>Documento sin título</title> <style type="text/css"> table { text-align: left; } ...
  #1 (permalink)  
Antiguo 23/09/2012, 21:10
Avatar de edwar1970  
Fecha de Ingreso: septiembre-2012
Ubicación: Santiago de Chile, Chile
Mensajes: 9
Antigüedad: 11 años, 7 meses
Puntos: 0
Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

mi formulario ingreso1

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/stylo.css"/>
<title>Documento sin título</title>
<style type="text/css">
table {
text-align: left;
}
</style>
</head>

<body>

<center>
<H2 style="color: #306">INGRESO DE CLIENTES</H2>
<P></P>
<form name="miform" id="form" action="guardar_cliente.php" method="post">
<table width="338" border="0">
<tr>
<th width="88" scope="row">Fecha </th>
<td width="240"><input type="text" name="fecha" size="36" maxlength="36" required="required" /></td>
</tr>
<tr>
<th scope="row">Hora </th>
<td><input type="text" name="hora" size="36" maxlength="36 "required="required" /></td>
</tr>
<tr>
<th scope="row">Movil </th>
<td><input type="text" name="movil" size="36" maxlength="17"required="required" /></td>
</tr>
<tr>
<th scope="row">Cliente </th>
<td><input type="text" name="cliente" size="36" maxlength="36" required="required" id="direccion4" /></td>
</tr>
<tr>
<th scope="row">Convenio </th>
<td><input type="text" name="convenio" size="36" maxlength="11" required="required" /></td>
</tr>
<tr>
<th scope="row">Costo </th>
<td><input type="text" name="costo" size="36" maxlength="36 "required="required" /></td>
</tr>
<tr>
<th scope="row">Origen </th>
<td><input type="text" name="origen" size="36" maxlength="17"required="required" /></td>
</tr>
<tr>
<th scope="row">Destino </th>
<td><input type="text" name="destino" size="36" maxlength="36" required="required" id="direccion3" /></td>
</tr>
<tr>
<th scope="row">Kilometro </th>
<td><input type="text" name="km" size="36" maxlength="11" required="required" /></td>
</tr>
<tr>
<th scope="row">Minutos </th>
<td><input type="text" name="min" size="36" maxlength="36 "required="required" /></td>
</tr>
<tr>
<th scope="row">Taximetro </th>
<td><input type="text" name="taximetro" size="36" maxlength="17"required="required" /></td>
</tr>
<tr>
<th scope="row">Tag </th>
<td><input type="text" name="tag" size="36" maxlength="36" required="required" id="direccion2" /></td>
</tr>
<tr>
<th scope="row">Peaje </th>
<td><input type="text" name="peaje" size="36" maxlength="11" required="required" /></td>
</tr>
<tr>
<th scope="row">Vale </th>
<td><input type="text" name="vale" size="36" maxlength="36 "required="required" /></td>
</tr>
<tr>
<th scope="row">Total </th>
<td><input type="text" name="total" size="36" maxlength="17"required="required" /></td>
</tr>
</table>
<tr>
<th scope="row"></th>
<td><input type="submit" value="Guardar" size="30" /></td>
</tr>
</table>

<input type="reset" name="button" id="button" value="Restablecer">
</form>

</center>
</body>
</html>

y mi archivo de guardar cliente

<!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=utf-8" />
<title></title>
</head>

<body>
<?php
include"clases/conex_serv.php";
// codigo para modificar registro
$link = new DB;
$link->conectar();
// codigo de ingreso de pacientes
// primero se capturan las variables post del formulario

if(isset($_POST))

{
// consulta de insercion de clientes
$insert=@mysql_query("INSERT INTO acomercial
(
(
fecha,
hora,
movil,
cliente,
convenio,
costo,
origen,
destino,
km,
min,
taximetro,
tag,
peaje,
vale,
total

) values(
'$_POST[fecha]',
'$_POST[hora]',
'$_POST[movil]',
'$_POST[cliente]',
'$_POST[convenio]'
'$_POST[costo]',
'$_POST[origen]',
'$_POST[destino]',
'$_POST[km]',
'$_POST[min]'
'$_POST[taximetro]',
'$_POST[tag]',
'$_POST[peaje]',
'$_POST[vale]',
'$_POST[total]'


)");
if($insert)
{
echo'<script type="text/javascript"> alert("Se ha guardado el registro exitosamente...");</script>';// mensaje al usuario
echo'<script type="text/javascript">location="ingreso1.php";</script>';// se redirecciona
}

else
{
echo'<script type="text/javascript">alert("Error al guardar el registro...");</script>';// mensaje al usuario
echo'<script type="text/javascript">location="ingreso1.php";</script>';// redireccion

}

}

?>
</body>
</html>

y mi tabla en mi base de datos esta la cree asi

CREATE TABLE acomercial(
id_acomercial int (10) not null auto_increment,
fecha varchar (15) not null,
hora varchar (15) not null,
movil varchar (10) not null,
cliente varchar (255) not null,
convenio varchar (12) not null,
costo varchar (15) not null,
origen varchar (255) not null,
destino varchar (255) not null,
km varchar (10) not null,
min varchar (10) not null,
taximetro varchar (10) not null,
tag varchar (10) not null,
peaje varchar (10) not null,
vale varchar (10) not null,
total varchar (10) not null,
primary key(id_acomercial)
engine=inb


de antemano gracias a quien colabora
  #2 (permalink)  
Antiguo 23/09/2012, 22:34
Avatar de xIamAlex  
Fecha de Ingreso: abril-2012
Ubicación: Venezuela
Mensajes: 118
Antigüedad: 12 años
Puntos: 23
Respuesta: Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

Utiliza una disyunción después de llamar a la función mysql_query, (or) y luego termina el programa pasando como parámetro el error mysql, así:

Código PHP:
$insert=mysql_query("INSERT INTO acomercial 


fecha, 
hora, 
movil,
cliente,
convenio, 
costo, 
origen,
destino,
km, 
min, 
taximetro,
tag,
peaje,
vale,
total

) values(
'$_POST[fecha]',
'$_POST[hora]',
'$_POST[movil]',
'$_POST[cliente]',
'$_POST[convenio]'
'$_POST[costo]',
'$_POST[origen]',
'$_POST[destino]',
'$_POST[km]',
'$_POST[min]'
'$_POST[taximetro]',
'$_POST[tag]',
'$_POST[peaje]',
'$_POST[vale]',
'$_POST[total]'


)"
) or die(mysql_error()); 
__________________
Las personas quieren autos, casas, teléfonos, dinero, poder, ser famosos, parejas, en fin.. yo solo quiero ser libre y feliz.
  #3 (permalink)  
Antiguo 24/09/2012, 14:14
Avatar de edwar1970  
Fecha de Ingreso: septiembre-2012
Ubicación: Santiago de Chile, Chile
Mensajes: 9
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

ahora me arroja 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 '( fecha, ' at line 3
  #4 (permalink)  
Antiguo 24/09/2012, 14:33
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

Copy+Paste sin una revisión de lo que pones, es una mala práctica...
Hay un doble paréntesis inicial al listar los campos de la tabla.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #5 (permalink)  
Antiguo 24/09/2012, 14:53
Avatar de edwar1970  
Fecha de Ingreso: septiembre-2012
Ubicación: Santiago de Chile, Chile
Mensajes: 9
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Detectar el tipo de error en MYSQL con PHP AL INGRESAR DATOS

Muchas gracias GNZSOLOYO esta funcionando ok
te hago una consulta como podria hacer para que esos mismos datos de la tabla se genere un reporte en exel

gracias

Etiquetas: formulario, html, input, mysql, tipo
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 04:54.