lundi 23 décembre 2019

span is still showing for some reason in php if statement

So I have two if statements for one of the fields of the form I'm working on. One is to check if the field(email) is empty or not, and the other one is to check if the email typed is in a right format. If a statement is false, it should show an error message with span tag. However, a span tag is still showing in the code even though the statement is true.

Here is the code.


<?php if( empty($data['email']) ): ?>
    <span class="error_list"><?php echo $error[5]; ?></span>
<?php endif; ?>
<?php if( !preg_match( '/^[0-9a-zA-Z_.\/?-]+@([0-9a-zA-Z-]+\.)+[0-9a-zA-Z-]+$/', $data['email']) ): ?>
    <span class="error_list"><?php echo $error[6]; ?></span>
<?php endif; ?>

I'm assuming there's something wrong with the way I put span tags in if statements, but I'm not sure.

I would appreciate any comments. Thank you.

Aucun commentaire:

Enregistrer un commentaire