
12/03/2010, 13:44
|
| | Fecha de Ingreso: enero-2009
Mensajes: 56
Antigüedad: 16 años, 2 meses Puntos: 0 | |
Respuesta: Enviar datos a mysql - Solucionado Ya funciona el codigo.
Aki lo dejo
Archivo - insertar_datos.php
Código:
<?php
if ($_POST['submit']){
$Nombre = $_POST['Nombre'];
$Apellido1 = $_POST['Apellido1'];
$Apellido2 = $_POST['Apellido2'];
$Dni = $_POST['Dni'];
$Email = $_POST['Email'];
$Telefono = $_POST['Telefono'];
$Fechainicio = $_POST['Fechainicio'];
$Fechafin = $_POST['Fechafin'];
$Personas = $_POST['Personas'];
$Comentario = $_POST['Comentario'];
} else {
echo "No se ha clicado el botón";
}
$link = mysql_connect("Server","usuario","contraseña");
mysql_select_db("basededatos",$link);
mysql_query("INSERT INTO Tabla (id, Nombre, Apellido1, Apellido2, Dni, Telefono, Email, Fechainicio, Fechafin, Personas, Comentario, Reservado, Cancelado)
VALUES ('', '$Nombre', '$Apellido1', '$Apellido2', '$Dni', '$Telefono', '$Email', '$Fechainicio', '$Fechafin', '$Personas', '$Comentario', '', '')",$link);
// Ahora comprobaremos que todo ha ido correctamente
$my_error = mysql_error($link);
if(!empty($my_error)) {
echo "Ha habido un error al insertar los valores. $my_error";
} else {
echo "Se ha hecho la Reserva correctamente.";
}
?>
y aki el archivo HTML - Reserva.html
Código:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Reservas</title>
</head>
<body>
<form action="insertar_datos.php" method="post" name="webtaller">
<div align="center"><center><table border="0" cellpadding="0"
cellspacing="0">
<tr>
<td>Nombre:</td>
<td><input type="text" size="20" name="Nombre"></td>
</tr>
<tr>
<td>Apellido 1: </td>
<td><input type="text" size="20" name="Apellido1"></td>
</tr>
<tr>
<td>Apellido 2:</td>
<td><input type="text" size="20" name="Apellido2"></td>
</tr>
<tr>
<td>D.N.I:</td>
<td><input type="text" size="20" name="Dni"></td>
</tr>
<tr>
<td>Teléfono:</td>
<td><input type="text" size="20" name="Telefono"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" size="20" name="Email"></td>
</tr>
<tr>
<td>Fecha Inicio</td>
<td><input type="text" size="20" name="Fechainicio"></td>
</tr>
<tr>
<td>Fecha Fin</td>
<td><input type="text" size="20" name="Fechafin"></td>
</tr>
<tr>
<td>Personas</td>
<td><input type="text" size="20" name="Personas"></td>
</tr>
<tr>
<td>Comentario</td>
<td><textarea name="Comentario" rows="5" cols="30"></textarea></td>
</tr>
</table>
</center></div><p align="center"><input type="submit"
name="submit" value="Enviar"></p>
</form>
</body>
</html>
Espero que os sirva de ayuda |