I am trying to make a login page. I've a database in which i have created a table named users, there are 2 fields which are need to be checked for login which are "username" & "password"..
Whenever user logs into the page & if the name is present in the table than it should log in else it should not and give error.
But 1 more error occurs in my code that when i use isset function to check my textfields it always returns me the string which is echoed in the else statement. (i.e "Something is wrong") which will be shown in the code below.
<!DOCTYPE html>
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$db_connect = mysqli_connect($hostname, $username, $password);
if (!$db_connect){
die("Database Connection Failed: " . mysql_error());
}
$db_select = mysqli_select_db($db_connect,"hamdard_attendance");
if (!$db_select){
die("Database Selection Failed: " . mysql_error());
}
?>
<html>
<head>
<title>Quality Management Cell</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<link rel="stylesheet" type="text/css" href="demo.css" media="all" />
</head>
<body>
<?php
if(isset($_POST['name'])){
$name=$_POST['name'];
}
else {
echo "Something is wrong";
}
if(isset($_POST['email'])){
$mail=$_POST['email'];
}
else {
echo "Something is wrong";
}
if(isset($_POST['username'])){
$user_name=$_POST['username'];
}
else {
echo "Something is wrong";
}
if(isset($_POST['password'])){
$user_password=$_POST['password'];
}
else {
echo "Something is Wrong";
}
if(isset($_POST['phone'])){
$phone_no = $_POST['phone'];
}
else {
echo "Something is Wrong";
}
$db_query = mysqli_query($db_connect, "INSERT INTO users(name, email, user_name, user_pass, contact_number)VALUES('". $name. "','".$mail."', '".$user_name."','".$user_password."','". $phone_no."')");
if(!$db_query){
die("Database Query Failed: " . mysql_error());
}
?>
<div class="container">
<!-- freshdesignweb top bar -->
<div class="freshdesignweb-top">
<a href="http://www.freshdesignweb.com" target="_blank">Home</a>
<span class="right">
<a href="http://www.freshdesignweb.com/beautiful-registration-form-with-html5-and-css3.html">
<strong>Back to Login Page</strong>
</a>
</span>
<div class="clr"></div>
</div><!--/ freshdesignweb top bar -->
<header>
<h1><span>Hamdard Institute of Information Technology</span> Quality Management Cell Registration</h1>
</header>
<div class="form">
<form id="contactform" method="post" action="index.php">
<p class="contact"><label for="name">Name</label></p>
<input id="name" name="name" value="name" placeholder="First and last name" required tabindex="1" type="text">
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" placeholder="example@domain.com" required type="email">
<p class="contact"><label for="username">Create a username</label></p>
<input id="username" name="username" placeholder="username" required tabindex="2" type="text">
<p class="contact"><label for="password">Create a password</label></p>
<input type="password" id="password" name="password" required>
<p class="contact"><label for="repassword">Confirm your password</label></p>
<input type="password" id="repassword" name="repassword" required>
<fieldset>
<label>Birthday</label>
<label class="month">
<select class="select-style" name="BirthMonth">
<option value="">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03" >March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12" >December</option>
</label>
</select>
<label>Day<input class="birthday" maxlength="2" name="BirthDay" placeholder="Day" required></label>
<label>Year <input class="birthyear" maxlength="4" name="BirthYear" placeholder="Year" required></label>
</fieldset>
<select class="select-style gender" name="gender">
<option value="select">i am..</option>
<option value="m">Male</option>
<option value="f">Female</option>
<option value="others">Other</option>
</select><br><br>
<p class="contact"><label for="phone">Mobile phone</label></p>
<input id="phone" name="phone" placeholder="phone number" required type="text"> <br>
<input class="buttom" name="submit" id="submit" tabindex="5" value="Register" type="submit">
</form>
</div>
</div>
</body>
</html>
<?php
mysqli_close($db_connect);
?>
Kindly help me out in removing this error & kindly tell me that is this code correct for the login scenario which i have explained?