index.php
Código PHP :
<html> <head> <title></title> <script language="JavaScript" type="text/javascript" src="ajax.js"> </script> </head> <body> <form name="DNI_USER" action="" onsubmit="sendDatUser(); return false"> <h2> </h2> <table> <tr> <td>user</td> <td> <label> <input name="DNI" type="text" /> </label> </td> </tr> <tr> <tr> <td> </td> <td> <label> <input type="submit" name="Submit" value="IN" /> </label> </td> <td>& nbsp;</td> <td> <label> <input type="submit" name="Submit" value="OUT" /> </label> </td> </tr> </table> </form> <div id="resultado"> <?php include( 'consult.php');?> </div> </body> </html>
ajax.js
Código Javascript :
//FUNCTION SEND POST A REG.PHP
Function objetoAjax() {
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
// JavaScript Document
// Función para recoger los datos de PHP según el navegador, se usa siempre.
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//Función para recoger los datos del formulario y enviarlos por post
function sendDatUser() {
divResultado = document.getElementById('resultado');
DNI = document.DNI_USER.DNI.value;
Submit = document.DNI_USER.Submit.value;
ajax = objetoAjax();
//uso del medotod POST
//archivo que realizará la operacion
//registro.php
ajax.open("POST", "reg.php", true);
ajax.onreadystatechange = function() {
if (ajax.readyState == 3) {
divResultado.innerHTML = ajax.responseText
ClearCamps();
}
}
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("DNI=" + DNI + "&Submit=" + Submit)
}
//función para limpiar los campos
function LimpiarCampos() {
document.sendDatUser.nombre.value = "";
document.sendDatUser.nombre.focus();
}**reg.php**
Código PHP :
<?php
//These lines of code are connecting to the database further wherein the Submit field to load the variable field from the Post included
//INSERT DATA IN MYSQL
$bd_host = "localhost";
$bd_usuario = "root";
$bd_password = "";
$bd_base = "test";
//conecction a la base de datos
$con = mysql_connect($bd_host, $bd_usuario, $bd_password);
mysql_select_db($bd_base, $con);
//campos capturados
$DNI=$_POST['DNI'];
$Estatus=$_POST['Submit'];
$Date=date('Y-m-d');
$Time=date('H:i:s');
$Host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
//insertar campo en la base de datos
$sql="INSERT INTO usuario (iduser, DNI, Estatus, Date, Time, Host) VALUES ('?','$DNI', '$Estatus', '$Date', '$Time', '$Host')";
mysql_query($sql,$con) or die('Error. '.mysql_error());
include('consult.php');
?>al insertar me muestra la siguiente tabla con el campo Estado vacío.

Gracias
