PHP - Problemas al insertar datos!

 
Vista:
sin imagen de perfil

Problemas al insertar datos!

Publicado por Rafael Hurtado (54 intervenciones) el 22/09/2012 21:12:29
Bien me encuentro encerrado en problema con PHP y MYSQL el.... explico que me pasa.....


Tengo una pagina en HTML donde tengo un FORM, con una variada de campos de textos, resulta que hago un script en PHP donde explico que debe hacer, pero cuando le doy al boton de enviar, me dice un mensaje que yo mismo puse "Problemas al introducir datos" he revisado todo y aparentemente todo esta bien tal cual como los consejos que me han dado algunos tutoriales......

No me arroja ningun parse error....

Ya no se que hacer para que funcione y me agregue los datos a la base de datos que he creado en phpmyadmin.

Anexo el HTML y el SCRIPT php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!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>
<style type="text/css">
<!--
.Estilo1 {
	font-size: 10px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.Estilo2 {
	font-size: x-large;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.Estilo3 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
	font-style: italic;
	font-size: small;
}
-->
</style>
</head>
 
<body>
<div align="center">
  <p><img src="logo.jpg" width="150" height="146" /></p>
</div>
<p align="center" class="Estilo2"><u>Registro de Alquiler</u></p>
<table width="976" height="348" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" valign="top"><div align="center">
      <form id="form1" name="form1" method="post" action="insertar.php">
        <hr color ="Black" class="Estilo1" />
        <table width="701" border="0" cellpadding="1" cellspacing="1" class="Estilo1">
          <tr>
            <td width="53">Empresa:</td>
            <td width="144"><input name="empresa" type="text" id="empresa" /></td>
            <td width="24">RIF:</td>
            <td width="144"><input name="rif" type="text" id="rif" /></td>
            <td width="60">Telefonos:</td>
            <td width="257"><input name="telefono" type="text" id="telefono" size="12" />
              <input name="telefono2" type="text" id="telefono2" size="12" /></td>
          </tr>
        </table>
        <table width="371" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td valign="top" class="Estilo1">Email:</td>
            <td valign="top" class="Estilo1"><input name="mail" type="text" id="mail" /></td>
            <td valign="top" class="Estilo1">Direccion:</td>
            <td class="Estilo1"><textarea name="domicilio" cols="35" rows="4" id="domicilio"></textarea></td>
          </tr>
        </table>
        <p align="left" class="Estilo3"><br />
          <u>Registro de Ejecutivo.</u></p>
        <table width="777" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td width="48" class="Estilo1">Nombre:</td>
            <td width="146" class="Estilo1"><input name="nombre" type="text" id="nombre" /></td>
            <td width="49" class="Estilo1">Apellido:</td>
            <td width="146" class="Estilo1"><input name="apellido" type="text" id="apellido" /></td>
            <td width="80" class="Estilo1">Identificacion:</td>
            <td width="85" class="Estilo1"><input name="identificacion" type="text" id="identificacion" size="14" /></td>
            <td width="54" class="Estilo1"><div align="right">E-mail</div></td>
            <td width="144" class="Estilo1"><input name="email" type="text" id="email" /></td>
          </tr>
        </table>
        <table width="674" border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td width="107" valign="top"><div align="right"><span class="Estilo1">Direccion</span>:</div></td>
            <td width="186"><textarea name="direccion" id="direccion"></textarea></td>
            <td width="60" valign="top"><span class="Estilo1">Telefonos:</span></td>
            <td width="308" valign="top"><input name="telefono3" type="text" id="telefono3" size="12" />
              <input name="telefono4" type="text" id="telefono4" size="12" /></td>
          </tr>
        </table>
        <table width="200" border="0" cellpadding="1" cellspacing="1" class="Estilo1">
          <tr>
            <td>Modelo:</td>
            <td><input name="modelo" type="text" id="modelo" /></td>
            <td>Placa:</td>
            <td><input name="placa" type="text" id="placa" /></td>
            <td>Color:</td>
            <td><input name="color" type="text" id="color" /></td>
          </tr>
        </table>
        <table width="702" border="0" cellpadding="1" cellspacing="1" class="Estilo1">
          <tr>
            <td width="21" valign="top">KM:</td>
            <td width="154" valign="top"><input name="km" type="text" id="km" /></td>
            <td width="72" valign="top">Observacion</td>
            <td width="198" valign="top"><textarea name="observacion" id="observacion"></textarea></td>
            <td width="94" valign="top"><div align="right">Fecha de salida:</div></td>
            <td width="48" valign="top"><input name="salida" type="text" id="salida" size="8" /></td>
            <td width="30" valign="top">COD:</td>
            <td width="60" valign="top"><input name="codigo" type="text" id="codigo" size="10" /></td>
          </tr>
        </table>
        <p>
          <input type="submit" name="Submit" value="Procesar" />
          <input type="reset" name="Submit2" value="Cancelar" />
        </p>
        </form>
      </div></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>


SCRIPT PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?
//Comprobar que nigun campo este vacio//
 
if (isset ($_POST['empresa']) && !empty ($_POST['empresa']) &&
		($_POST['rif']) && !empty ($_POST['rif']) &&
		($_POST['telefono']) && !empty ($_POST['telefono']) &&
		($_POST['telefono2']) && !empty ($_POST['telefono2']) &&
		($_POST['mail']) && !empty ($_POST['mail']) &&
		($_POST['domicilio']) && !empty ($_POST['domicilio']) &&
		($_POST['nombre']) && !empty ($_POST['nombre']) &&
		($_POST['apellido']) && !empty ($_POST['eapellido']) &&
		($_POST['identificacion']) && !empty ($_POST['identificacion']) &&
		($_POST['email']) && !empty ($_POST['email']) &&
		($_POST['direccion']) && !empty ($_POST['direccion']) &&
		($_POST['telefono3']) && !empty ($_POST['telefono3']) &&
		($_POST['telefono4']) && !empty ($_POST['telefono4']) &&
		($_POST['modelo']) && !empty ($_POST['modelo']) &&
		($_POST['placa']) && !empty ($_POST['placa']) &&
		($_POST['color']) && !empty ($_POST['color']) &&
		($_POST['km']) && !empty ($_POST['km']) &&
		($_POST['observacion']) && !empty ($_POST['observacion']) &&
		($_POST['salida']) && !empty ($_POST['salida']) &&
		($_POST['codigo']) && !empty ($_POST['codigo']))
		{
		 //Conectando con la Base de Datos//
 
		 $conectar = mysql_connect ("localhost", "root","1234");
		  mysql_select_db("alquiler", $conectar);
 
		//Insertando datos en la Tabla//
			mysql_query ("INSERT INTO vehiculos (EMPRESA,RIF,TELEFONO,TELEFONO2,MAIL,DOMICILIO,
												 NOMBRE,APELLIDO,IDENTIFICACION,EMAIL,DIRECCION,
												 TELEFONO3,TELEFONO4,MODELO,PLACA,COLOR,KM,OBSERVACION,
												 SALIDA,CODIGO)
			
			VALUES ('{['empresa']}','{['rif']}','{['telefono']}','{['telefono2']}','{['mail']}','{['domicilio']}','
					{['nombre']}','{['apellido']}','{['identificacion']}','{['email']}','{['direccion']}','{['telefono3']}','
					{['modelo']}','{['placa']}','{['color']}','{['km']}','{['observacion']}',''{['salida']}','{['codigo']}')", $conectar);
 
					//Comprobar que todo ha funcionado bien//
 
			$mierror = mysql_error ($conectar);
				if (!empty ($mierror)){
					echo "Ha ocurrido un error al insertar valores. $mierror";
 
			}else{
			  echo "Datos insertados correctamente";
		}
 
		}else {
		  echo "Error al introducir Datos";
		  }
?>


ESPERO QUE ME AYUDE Y ESTARE MUY AGRADECIDO
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problemas al insertar datos!

Publicado por xve (6935 intervenciones) el 23/09/2012 08:54:00
Hola Rafael, la verdad es que algunas cosas de tu codigo no las habia visto nunca, como por ejemplo, cojer el valor del post así: {['empresa']}... yo creo que no funciona!!!

También he encontrado un error...
1
'{['observacion']}',''{['salida']}'

Te sobra una comilla...

Me he permitido rehacer tu script de php para poder ver si veo lo que esta pasando...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
print_r($_POST);
if ($_POST['empresa'] &&
    $_POST['rif'] &&
    $_POST['telefono'] &&
    $_POST['telefono2'] &&
    $_POST['mail'] &&
    $_POST['domicilio'] &&
    $_POST['nombre'] &&
    $_POST['apellido'] &&
    $_POST['identificacion'] &&
    $_POST['email'] &&
    $_POST['direccion'] &&
    $_POST['telefono3'] &&
    $_POST['telefono4'] &&
    $_POST['modelo'] &&
    $_POST['placa'] &&
    $_POST['color'] &&
    $_POST['km'] &&
    $_POST['observacion'] &&
    $_POST['salida'] &&
    $_POST['codigo']
{
    //Conectando con la Base de Datos//
 
    $conectar = mysql_connect ("localhost", "root","1234");
    mysql_select_db("alquiler", $conectar);
 
    //Insertando datos en la Tabla//
    mysql_query ("INSERT INTO vehiculos
        (
            EMPRESA,RIF,TELEFONO,TELEFONO2,MAIL,DOMICILIO,NOMBRE,APELLIDO,
            IDENTIFICACION,EMAIL,DIRECCION,TELEFONO3,TELEFONO4,MODELO,PLACA,
            COLOR,KM,OBSERVACION,SALIDA,CODIGO
        )VALUES(
            '".$_POST['empresa']."','".$_POST['rif']."',
            '".$_POST['telefono']."','".$_POST['telefono2']."',
            '".$_POST['mail']."','".$_POST['domicilio']."',
            '".$_POST['nombre']."','".$_POST['apellido']."',
            '".$_POST['identificacion']."','".$_POST['email']."',
            '".$_POST['direccion']."','".$_POST['telefono3']."',
            '".$_POST['modelo']."','".$_POST['placa']."','".$_POST['color']."',
            '".$_POST['km']."','".$_POST['observacion']."',
            '".$_POST['salida']."','".$_POST['codigo']."'
        )", $conectar);
 
    //Comprobar que todo ha funcionado bien//
 
    $mierror = mysql_error ($conectar);
    if ($mierror)
    {
        echo "Ha ocurrido un error al insertar valores. $mierror";
    }else{
        echo "Datos insertados correctamente";
    }
}else{
    echo "Error al introducir Datos";
}
?>


Fijate en la primera linea, que te muestra el contenido de las variables pasadas por post... comprueba que todas las variables del if tengan valor, sino, no entrara nunca a guardar los datos.

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problemas al insertar datos!

Publicado por Rafael Hurtado (54 intervenciones) el 23/09/2012 17:09:38
Ok muchas gracias por tu ayuda xve...

Hablando del tema, hice las modificaciones pertinente que me dijiste en el post anterior.... corregi algunas cosas ahora sucede que cuando le doy al boto de enviar.... me arroja lo siguiente

Array ( [empresa] => 1 [rif] => 1 [telefono] => 1 [telefono2] => 1 [mail] => 1 [domicilio] => 1 [nombre] => 1 [apellido] => 1 [identificacion] => 1 [email] => 1 [direccion] => 1 [telefono3] => 1 [telefono4] => 1 [modelo] => 1 [placa] => 1 [color] => 1 [km] => 1 [observacion] => 1 [salida] => 1 [codigo] => 11 [Submit] => Procesar ) Ha ocurrido un error al insertar valores. Column count doesn't match value count at row 1

Espero que me pueda ayudar
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problemas al insertar datos!

Publicado por xve (6935 intervenciones) el 23/09/2012 18:06:26
Hola Rafael, el array que te muestra es de la linea print_r()...

El error que te da, creo que es que hay diferente numero de valores en el insert.. es decir, en el primer paréntesis hay n valores y en el segundo difiere...
(.........) values (.........)
Revísalo...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problemas al insertar datos!

Publicado por Rafael Hurtado (54 intervenciones) el 23/09/2012 18:12:13
Correcto amigo ya resolvi la situacion ya me agrega la informacion a la BD de datos....... satisfactoriamente.... Pero ahora le tengo una simple pregunta.... Yo quisiera que cuando le de al boton de enviar, no salga el ARRAY ([empresa] => 1 y todo los otros campos), y si puede otra cosa mas es que quiera cambiarle el formato a la BD, por ejemplo en el campo de salida el formato es DATE pero me agrega es esto 0000-00-00, quisiera que fuera dd/mm/0000.....

De verdad me siento muy agradecido por su ayuda!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar