hello po sa mga web developer. Patulong namn po. May ginagawa po kase akong pop up log in form.
eto po ung codes sa form
[CODE title="Form (login_form.php)"]<form action="login_conn.php" method="post">
<input type=" text" name="email" id="email" placeholder="email">
<input type="password" name="password" id="password" placeholder="password">
<button name="submit" id="submit">Log in</button>
<p id="result"></p>
</form>[/CODE]
And eto naman po ung codes para ma verify kung naka register po ung user which is gumagana naman po.
[CODE title="Verify/Connection (login_conn.php)"]<?php
if (isset($_POST["submit"])) {
$dbservername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "userdb";
$email = $_POST['email'];
$password = $_POST['password'];
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
if (!$conn) {
die("Connection Failed: " . mysqli_connect_error());
}
function uidExists($conn, $email)
{
$sql = "SELECT * FROM users WHERE email_address = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: index.php?error=stmterror");
exit();
}
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($resultData)) {
return $row;
} else {
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
function loginUser($conn, $email, $password)
{
$uidExists = uidExists($conn, $email);
if ($uidExists === false) {
echo "email does not exist";
exit();
}
$pwdEncrypt = $uidExists["password"];
$checkPwd = password_verify($password, $pwdEncrypt);
if ($checkPwd === false) {
echo "wrong password";
exit();
} else if ($checkPwd === true) {
session_start();
$session["uid"] =$uidExists["_id"];
$session["uemail"] =$uidExists["email"];
header("location: index.php?error=loggedin");
exit();
}
}
loginUser($conn, $email, $password);
} else {
header("location: index.php");
}[/CODE]
Ang gusto ko po sana eh ung result nya po na "email does not exist" or "wrong password"
eh mag appear sa #result ng Form instead na iopen nya yung connection page at
doon mag appear yung result once na na click ung submit btn. And dapat hindi mag refresh sa Form para hindi mag close ung pop
up form.
Sorry po newbie lang po sa web developing.
Sana po may makatulong. Need lang po talaga.
Salamat po....
eto po ung codes sa form
[CODE title="Form (login_form.php)"]<form action="login_conn.php" method="post">
<input type=" text" name="email" id="email" placeholder="email">
<input type="password" name="password" id="password" placeholder="password">
<button name="submit" id="submit">Log in</button>
<p id="result"></p>
</form>[/CODE]
And eto naman po ung codes para ma verify kung naka register po ung user which is gumagana naman po.
[CODE title="Verify/Connection (login_conn.php)"]<?php
if (isset($_POST["submit"])) {
$dbservername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "userdb";
$email = $_POST['email'];
$password = $_POST['password'];
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
if (!$conn) {
die("Connection Failed: " . mysqli_connect_error());
}
function uidExists($conn, $email)
{
$sql = "SELECT * FROM users WHERE email_address = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: index.php?error=stmterror");
exit();
}
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($resultData)) {
return $row;
} else {
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
function loginUser($conn, $email, $password)
{
$uidExists = uidExists($conn, $email);
if ($uidExists === false) {
echo "email does not exist";
exit();
}
$pwdEncrypt = $uidExists["password"];
$checkPwd = password_verify($password, $pwdEncrypt);
if ($checkPwd === false) {
echo "wrong password";
exit();
} else if ($checkPwd === true) {
session_start();
$session["uid"] =$uidExists["_id"];
$session["uemail"] =$uidExists["email"];
header("location: index.php?error=loggedin");
exit();
}
}
loginUser($conn, $email, $password);
} else {
header("location: index.php");
}[/CODE]
Ang gusto ko po sana eh ung result nya po na "email does not exist" or "wrong password"
eh mag appear sa #result ng Form instead na iopen nya yung connection page at
doon mag appear yung result once na na click ung submit btn. And dapat hindi mag refresh sa Form para hindi mag close ung pop
up form.
Sorry po newbie lang po sa web developing.
Sana po may makatulong. Need lang po talaga.
Salamat po....