I am new in programming. I actually want to check user input value with stored value in database. Specially, email and password which is given by the user, print the details of that respective email id. Here is my code. Please help me to correct my code.
<?php
$conn = mysqli_connect('localhost', 'root', '', 'mydb');
$sql = "SELECT email, first FROM register";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Welcome " . $row["first"]. "<br>". "Your Email Id is: " . $row["email"] . "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
<?php
$conn = mysqli_connect('localhost', 'root', '', 'mydb');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "select * from register where email = '$username'";
$resultSet = mysqli_query($query, $conn);
if(mysqli_num_rows($resultSet) > 0){
$row = mysqli_fetch_assoc($resultSet);
if($row['password'] == $password){ // if you are using encryption like md5 or anything else then you have to add in this line accordingly
echo "Good, Logged In!";
}else{
echo "Oh No, password not correct!";
}
}else{
echo "Please enter correct email!";
}
<?php
$conn = mysqli_connect('localhost','root','','mydb');
$sql = "SELECT email,first FROM register where email=$_POST['form_ref_name'];
$result = mysqli_query($conn,$sql);
if($result){
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Welcome " . $row["first"]. "<br>". "Your Email Id is: " . $row["email"] . "<br>";
}
}
}
else {
echo "0 results";
}
mysqli_close($conn);
?>
try this It may help. Insted you can with $row varible it will contain values from DB.
u have use where condition as per mention below. i think help below query.
<?php
$email = $_POST['email'];
$password= $_POST['password'];
$sql = mysql_query("SELECT email,first FROM register WHERE email = $email and password = $password");
?>