PHP - 2 Submit en un from con php ajax y mysql

 
Vista:

2 Submit en un from con php ajax y mysql

Publicado por DAVIS (1 intervención) el 13/12/2015 16:00:11
Gracias por, No se inserta el campo Estado (campo vacío) la ayuda de mi desventaja es el siguiente:

**index.php**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->


<!-- Page Principal working method POST-->
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
<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>
			  <!-- CAMPO DE TEXTO -->
                <input name="DNI" type="text" />
              </label>
            </td>
          </tr>
          <tr>
            <tr>
              <td>&nbsp;</td>
              <td>
                <label>
				 <!-- ENVIAMOS EN la variable ENTRADA -->
                  <input type="submit" name="Submit" value="IN" />
                </label>
              </td>
              <td>& nbsp;</td>
                <td>
                  <label>
				  <!--ENVIAMOS LA VARIABLE SALIDA -->
                    <input type="submit" name="Submit" value="OUT" />
                  </label>
                </td>
            </tr>
        </table>
      </form>
      <div id="resultado">
        <?php include( 'consult.php');?>
      </div>
    </body>
 
    </html>


<!-- end snippet -->


**ajax.js**

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->

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
    //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();
    }

<!-- end snippet -->

**reg.php**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

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
<?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');
 
 
    ?>
<!-- end snippet -->


**No inserts the Status field (field empty)**



thank you.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder