Skip to content
Advertisement

Trouble Displaying Submitted Data to Log

<script>
function login() {
  var userN = document.getElementById("userN").value;
  var pin = document.getElementById("pin").value;

  if (userN == "") {
    alert("User name not entered");
    document.getElementById("userN").focus();
    }
    else if (pin == "") {
      alert("PIN Number not entered");
      document.getElementById("pin").focus();
      }
      else {
        var userAccount = "User Name:" + userN + "n" +
          "Pin:" + pin;
        alert("userAccount");
      }
    }
  </script>
</head>

<body>
  <h2>Please enter your User Name and PIN:</h2>
  <form name="formLogin" action="">
    <action="loginLog.php" method="post">
    <p><label for="userN">User Name: </label>
      <input type="text" name="userN" id="userN" size="20" maxlength="8" tabindex="1"></p>
    <p><label for="pin">PIN Number: </label>
      <input type="password" name="pin" id="pin" size="20" maxlength="8" tabindex="2"></p>

    <input type="submit" onclick="return login();" />
    <input type="reset" onclick="document.formLogin.userN.focus();" />
  </form>

I’m having an issue with $_Post to capture and echo to display data submitted on a login page. I’m not exactly sure what I’m missing to get this data on a login page to push to loginLog.php

Here’s my loginLog.php file

<body>
Welcome
<?php
    echo $_POST["userN"];

?>

<?php
    echo $_POST["pin"];
?>


</body>

Advertisement

Answer

Don’t forget adding method attribute with the value post as below:

<form name="formLogin" action="path/to/yourfile/loginLog.php" method="post">
    <action="loginLog.php" method="post">
    <p><label for="userN">User Name: </label>
      <input type="text" name="userN" id="userN" size="20" maxlength="8" tabindex="1"></p>
    <p><label for="pin">PIN Number: </label>
      <input type="password" name="pin" id="pin" size="20" maxlength="8" tabindex="2"></p>

    <input type="submit" onclick="return login();" />
    <input type="reset" onclick="document.formLogin.userN.focus();" />
  </form>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement