Shahar Galukman Shahar Galukman - 7 months ago 20
PHP Question

echo login error in different page, specific div

Delayed too long with this issue. I have a index.php including form and login.php handeling it.

How do I post the errors in a specific div in index.php?
Here is the Index.php container, no php code in idnex.php yet.

<div id="container">
<section>
<h1>ברוכים הבאים לאתר קופונים</h1>
<h2>המקום בו תוכלו למצוא קופונים בסביבתכם</h2>
<hr>
</section>

<section id="mainpage">
<p class="welcome">
אנא התחבר בכדי ליצור ולראות קופונים בקרבתך</br>
<a href="php/register.php">הירשם לאתר</a>
</p>

<form action="php/login.php" method="post" class="form">
<p class="email">
<input type="text" name="email" /> :דואר אלקטרוני</br>
</p>
<p class="password">
<input type="password" name="password" /> :סיסמא</br>
</p>
<p class="submit">
<input type="submit" value="היכנס" />
</p>
</form>
</section>
</div>


and here is the login.php error reporting section

//check matching input
if($email == $dbemail && $password = $dbpassword){
$_SESSION['email'] = $dbemail;
include('../index.php');
header('members.php');

}
else{
include('../index.php');
echo "Incorrect Password<style text-align:center;/>";
}
}

} else
include('../index.php');
die('<p class="error">User does not exist</p>');
} else
include('../index.php');
die('Please enter a Email and password');


tried this

include('../index.php');
die('<p class="error">User does not exist</p>');


can't manage to specifically position it under the Submit button (using margin: 0 auto so left and right changes)

Thanks for any help given

Answer

change your login.php file:

} else {
   // error happened
   $error = '<p class="error">User does not exist</p>'
   include('../index.php');
   exit;
...

and your index.php file:

<form action="php/login.php" method="post" class="form">
<?php
if(isset($error)) echo $error;
?>
<p class="email">
   <input type="text" name="email" /> :דואר אלקטרוני</br>
...