Trying to get code to search if '@' symbol is present in typed-in email address and echo if symbol is not. Everything works fine without the searching for @ code.
check.php
<?php
include '/connect.php'; //connects to mysql
$email = mysqli_real_escape_string($connect, $_POST['email']);
$check = mysqli_query($connect, "SELECT email FROM users WHERE email='$email'");
$check_num_rows = mysqli_num_rows($check);
if ($email==NULL) {
echo 'Enter an email';
} elseif (strlen($email)<6) {
echo 'Please enter a valid email';
} elseif (str($email).indexOf('@') == -1) {
echo 'Please enter a valid email';
} else {
if ($check_num_rows==0) {
echo 'Email valid';
} elseif ($check_num_rows==1) {
echo 'Email already registered';
}
}
register.php
<script type="text/javascript" src="/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function() {
$('#feedback_email').load('/check.php').show();
$('#email').keyup(function() {
$.post('/check.php', { email: form.email.value },
function(result) {
$('#feedback_email').html(result).show;
});
});
});
</script>
<form action="register.php" method="post" name="form">
<input id="email" type="text" name="email" placeholder="Email Address" maxlength="60" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>">
<div id="feedback_email"></div>
<p><center><input type="submit" name="submit" value="Register"></center>
</form>
EDIT: I do have a built in filter for the php back-end validation. However, I'm trying to do a front-end validation as well through these codes. If anyone knows how to fix my script please post. I'm receiving error
Call to undefined function str() in /check.php on line 13
Line 13
} elseif (str($email).indexOf('@') == -1) {