I have defined a variable with string value in library.php and I want to use it in another page client-login.php without useing an anchor tag.
library.php:
if(isset($_POST['client-login-submit'])){
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if($username == ""){
$login_error_message = 'Username field is required!';
}else if($password == ""){
$login_error_message = 'Password field is required!';
}else{
$id = Login($username, $password);
if($id > 0){
$_SESSION['id'] = $id; // Set Session
header("location: ../../main.php");
}else{
$login_error_message = 'Invalid login details!';
}
}
}
client-login.php:
<form action="inc/lib/library.php" method="post">
<h1>LOG IN</h1>
<input placeholder="Username" type="text" name="username" id="username">
<input placeholder="Password" type="password" name="password" id="password">
<input type="submit" name="client-login-submit" value="LOG IN">
<p>Forget Your Password? <a href="#">RESET</a></p>
<p><a href="client-sign-up.php">SIGN UP</a></p>
<?php
if ($login_error_message != "") {
echo '<p style="color: red;"><strong>Error: </strong> ' .$login_error_message. '</p>';
}
?>
</form>
this is the error I get in the place that $login_error_message must be shown after occuring error... :
Notice: Undefined variable: login_error_message in C:\xampp\htdocs\fashion\client-login.php on line 54
after submitting the form if there is an error then it must be shown but the error above is already shown even before clicking... and when I click on submit button it goes to library.php page which is blank.
Would you please help how to use $login_error_message in client-login.php? Thanks in advance...
Error: ' .isset($login_error_message)?$login_error_message:' '. '
'; – Sachin Aghera May 15 '18 at 11:55