conexion.php
Código
<?php ?>
funciones.php
Código
<?php function getParam($param, $default) { $result = $default; } return $result; } function sqlValue($value, $type) { $value = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($value) : mysql_escape_string($value); switch ($type) { case "text": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; case "int": break; case "double": break; case "date": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; } return $value; } ?>
insert-demo1.php
Código
<?php require("conexion.php"); // insertarmos el registro mysql_query("INSERT INTO producto (codigo, nombre, nota) VALUES ('Apple', '1 Infinite Loop, Cupertino', 899610)"); // obtenemos el ID del registro ?>
insert-demo2.php
Código
<?php require("conexion.php"); $status = ""; $codigo = $_POST["codigo"]; $nombre = $_POST["nombre"]; $nota = $_POST["nota"]; $sql = "INSERT INTO producto (codigo, nombre, nota) "; $sql.= "VALUES ('".$codigo."', '".$nombre."', '".$nota."')"; $status = "ok"; } ?> <!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>PHP con MySQL: Insertar datos en MySQL</title> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <body> <h3>Nueva Empresa</h3> <?php if ($status == "ok") { ?> <p class="confirm">Registro guardado correctamente</p> <?php } ?> <form method="post" id="frEmpresa" action="insert-demo2.php"> <label for="nombre">Nombre</label> <input type="text" id="nombre" name="nombre" /> <br /> <label for="direccion">Dirección</label> <input type="text" id="direccion" name="direccion" /> <br /> <label for="telefono">Telefono</label> <input type="text" id="telefono" name="telefono" /> <br /> <label for="bts"> </label> <button type="submit">Guardar</button> <button type="reset">Limpiar</button> </form> </body> </html>
insert-demo3.php
Código
<?php require("conexion.php"); require("funciones.php"); $status = ""; $nombre = sqlValue($_POST["codigo"], "text"); $direccion = sqlValue($_POST["nombre"], "text"); $telefono = sqlValue($_POST["nota"], "text"); $sql = "INSERT INTO producto (codigo, nombre, nota) "; $sql.= "VALUES ('".$codigo."', '".$nombre."', '".$nota."')"; echo $sql; $status = "ok"; } ?> <!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>PHP con MySQL: Insertar datos en MySQL</title> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <body> <h3>Nueva Empresa</h3> <?php if ($status == "ok") { ?> <p class="confirm">Registro guardado correctamente</p> <?php } ?> <form method="post" id="frEmpresa" action="insert-demo3.php"> <label for="nombre">Nombre</label> <input type="text" id="nombre" name="nombre" /> <br /> <label for="direccion">Dirección</label> <input type="text" id="direccion" name="direccion" /> <br /> <label for="telefono">Telefono</label> <input type="text" id="telefono" name="telefono" /> <br /> <label for="bts"> </label> <button type="submit">Guardar</button> <button type="reset">Limpiar</button> </form> </body> </html>
lo acomode asi no le ingrese mas campos solo esos 3 para probar pero nada todavia sigue sin ingresar campos