I am very new to html and php and need a little help. This is actually my first post on stackoverflow so I apologize if the content isn't done right.
I am asking for a username and password from a user and then I want to take that information and use it in a script that is run on the server via PHP.
The problem I'm having is that the first time a user goes to the html and fills out the form, the $_POST in the php file doesn't receive anything. I know that because I echoed the variables in the php file. But after the user presses the 'Back' button on the php page and returns back to the html, when going through it again, everything works fine.
So the code works, it just doesn't work the first time. Any ideas?
HTML:
<body>
<div class="loader" id="container" style="visibility:hidden;"></div>
<form method="post" action="Login_Page.php">
<b>Username:</b><input type="text" placeholder="University ID" name="userid" autofocus/>
<b>Password:</b><input type="password" placeholder="Password" name="pswrd"/>
<input type="submit" class="button" value="Submit" onclick="showDiv()"/>
</form>
</div>
</body>
CSS:
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('https://cdn.shopify.com/s/files/1/1247/2733/t/4/assets/loading.gif?11916921113420493983') 50% 50% no-repeat rgba(255, 255, 255, 0.3);
filter: alpha(opacity=60);
}
Script:
<script type="text/javascript">
showDiv = function() {
document.getElementById("container").style.visibility="visible";
}
</script>
PHP:
<?php
$username = $_POST["userid"];
$pswrd = $_POST["pswrd"];
echo $username;
echo $pswrd;
$cmd = "path/to/script.sh $username $pswrd";
exec($cmd, $output, $return);
if ($return != "0") {
echo '<h1><b>Login was unsuccessful. Please try again.</b></h1>';
echo '<form>';
echo '<input type="button" value="Back" onClick="history.go(-1);return true;"/>';
echo '</form>';
} else {
echo '<h1><b>Login was Successful.</b></h1>';
}
?>