<?php //$msg = $_POST['msg']; $usernameerr = $passerr = ""; $username = $pass = ""; //echo "<p>" . $msg . "</p>"; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["username"])) { $usernameerr = "Username is missing"; $valid = false; } else { $username = test_input($_POST["username"]); $valid = true; } if (empty($_POST["password"])) { $passerr = "Password is missing"; $valid = false; } else { $pass = test_input($_POST["password"]); $valid = true; } if($valid) { header('Location: http://localhost/tabs/validate_login.php'); exit(); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" style= " margin-left:25%; " > <table width= 100% height= 100%;> <tr> <td width = 60px><label for="username">Username</label></td> <td width = 60px><input type="text" name="username" id="username"></td> </tr> <tr> <td width = 60px><label for="password">Password</label></td> <td width = 60px><input name="password" type="password" id="password"></input></td> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </table> <table > <td width = 100px align="center"><input type="submit" value="Submit"/> <td width = 100px align = "center"><input type="reset" value="Reset"/> </tr> </table> </form>
<?php // Grab User submitted information $username = $_POST["username"]; $pass = $_POST["password"]; // Connect to the database $con=mysqli_connect("localhost","root","Quest1234","maintenance_help"); // Make sure we connected succesfully if(! $con) { die('Connection Failed'.mysql_error()); } // Select the database to use $result = mysqli_query($con,"SELECT username, pass FROM login WHERE username = '$username'"); $row = mysqli_fetch_array($result); $match = mysql_num_rows($result); if($row["username"]==$username && $row["pass"]==$pass) { //echo $username; //echo $pass; //echo "<p>" . $row['username'] . "</p>"; //echo "<p>" . $row['pass'] . "</p>"; echo "success"; // echo "<p> apple " . $match . "</p>"; //echo "<script> window.location.assign('stockform.php'); </script>"; } else { //$msg = "Invalid Username or Password"; //$_POST['msg']; //header('Location: http://localhost/tabs/login.php'); echo "invalid username or password"; } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)