A newbie IT student here trying to code my subject requirement which is a ecommerce web app. The problem that im having rn is with the login form that is written in Php. Regardless if the input that I type is right or wrong, the alert still displays "Please fill up all fields".
This is my Php Login Form
<?php
$conn = mysql_connect("localhost","root","1234");
if(!$conn)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("registration", $conn);
$email=$_POST["email"];
$pwd=md5($_POST["password"]);
$query = mysql_query("SELECT * FROM tbl_reg where password='$pwd' AND email='$email'",$conn);
$rows = mysql_num_rows($query);
if(!$email|| !$pwd)
{
echo"<script>alert(\"please fill up fields\");window.location='sign-in.html'</script>";
}
if ($rows == 1)
{
echo"<script>alert(\"login Succes\");window.location='index2.html'</script>";
}
else
{
$error = "Username or Password is invalid";
}
if ($rows == 0)
{
echo"<script>alert(\"Username or Password is Incorrect\");window.location='login.php'</script>";}
mysql_close($conn);
?>
Here is basically my HTML Login Form
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.104.2">
<title>Log in Form</title>
<link rel="canonical" href="https://getbootstrap.com/docs/5.2/examples/sign-in/">
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
</style>
<!-- Custom styles for this template -->
<link href="assets/css/signin.css" rel="stylesheet">
</head>
<body class="text-center">
<main class="form-signin w-100 m-auto">
<form method="post" action="login.php">
<img class="mb-4" src="../assets/brand/bootstrap-logo.svg" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
<div class="form-floating">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com" name="email">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" name="password">
<label for="floatingPassword">Password</label>
</div>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me" > Remember me
</label>
</div>
<button class="w-100 btn btn-lg btn-primary" type="submit"><a href="appDev Assignment/index.html">Sign in</a></button>
<p class="mt-5 mb-3 text-muted">© 2017–2022</p>
</form>
<center>
<p class="mt-5 mb-3 text-muted" id="q">©</p>
</center>
</main>
<script>
var category = 'happiness'
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/quotes?category=' + category,
headers: { 'X-Api-Key': 'ToCfG0A/2Y9rS7AiwSj0BA==5YvMUReDisFAtJ0P'},
contentType: 'application/json',
success: function(result) {
console.log(result);
var q=result;
var quote=result[0].quote;
console.log(quote);
let q1 = document.getElementById("q")
q1.textContent =quote
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
}
});
</script>
</body>
</html>
I have a pretty shitty Prof. who just posted the syntax in a Ppt. file without any kind of information. Just pure hard code. Nothing more. nothing less. without even a sliver of teaching. I tried everything from rewriting my code to dropping my database or deleting my Table but to no avail. I even tried to rewrite everything even the HTML form one. Please i need help because our midterms are just at the end of the month and i really need help.