I am trying to display a message if my database doesn't has that value. my code is:
$dbc = mysqli_connect($hn,$un,$pd,$db);
$query= "SELECT * FROM sign_up WHERE email = '{$email}'";
$result = mysqli_query($dbc,$query);
mysqli_close($dbc);
$row = mysqli_num_rows($result);
if($row==0){
$emailNoExistErr = 'Value not found.';
echo $emailNoExistErr;}
Now, Since from the beginning the value in mysqli_num_rows($result) is zero. The error is displayed from the time page loads. I want it to appear only when the value given by user in field is checked through database and it is not present.
please help. Thanks.
Full code update:
<body>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$email = $_POST['email'];
$password = $_POST['password'];
}
$dbc = mysqli_connect($hn,$un,$pd,$db);
$query= "SELECT * FROM sign_up WHERE email = '{$email}'";
$result_mail = mysqli_query($dbc,$query);
mysqli_close($dbc);
$row = mysqli_num_rows($result_mail);
?>
<div class="cover-container wrap">
<div id="signup-bg">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<ul class="form-style-1">
<li>
<label for="email">Email</label>
<input placeholder="Email*" type="email" name="email" id="email" required>
</li>
<span class="error"><?php
if($row==0){
$emailNoExistErr = 'This email is not signed up with us.';
echo $emailNoExistErr;}
?></span>
<li>
<label for="password">Password</label>
<input placeholder="Password*" type="password" name="password" id="password" onpaste="return false;" required>
</li>
<li>
<input type="submit" value="Sign in" name="sign_in" id="sign_in">
</li>
</ul>
</form>
</div>
</div>
</body>
isset($email)$email