I am using bassistance validation plugin and I need to check if the email already exists in my database, can someone ple开发者_StackOverflow社区ase provide a sample php code for the serverside portion of this? i don't simply want to echo true or false, i want the json solution with the message option too...
This doesn't include the database connection stuff, but figured you would not need that? If you do let me know and I'll provide that as well.
<?php
require_once('dbconnection.php');
$email = $_GET['email'];
mysqli_select_db($conn, $dbname);
$q = "SELECT Email FROM Users WHERE Email= '" . $email . "'";
$r = mysqli_query($conn, $q) or die(mysqli_error());
$totalRows = mysqli_num_rows($r);
if( $totalRows > 0 )
{
//email already exists in database, return false.
echo "false";
} else {
echo "true";
}
mysqli_free_result($r); //close connection
?>
精彩评论