I make UWP app with login and registration page
I use PHP and MYSQL as backend
But I want to check if the email exists and if it exists, send a message to my app and show it in MessageDialog
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri requestUri = new Uri("http://localhost/test/index.php");
HttpClient client = new HttpClient();
Dictionary<string, string> pairs = new Dictionary<string, string>();
pairs.Add("email", emailbox.Text);
pairs.Add("password", passwordbox.Text);
HttpFormUrlEncodedContent encodedContent = new HttpFormUrlEncodedContent(pairs);
await client.PostAsync(requestUri, encodedContent);
}
<?php
try
{
$bdd = new PDO("mysql:host=localhost;dbname=firstdb","root","");
}
catch(Exception $e)
{
die("ERROR".$e->getMessage());
}
$email = "";
$req = "";
$password = "";
if(isset($_POST['email']) && isset($_POST['password']))
{
$email = $_POST['email'];
$password = $_POST['password'];
$req = $bdd->prepare("INSERT INTO users(email,password) VALUES (:email,:password)");
$req->execute(array('email'=>$_POST['email'],'password'=>$_POST['password']));
}
?>
It works fine to insert data to SQL database but I don't know how to check if email already exist
check email is exist or not with select query. count result if exist then return message
if(isset($_POST['email']) && isset($_POST['password']))
{
$email = $_POST['email'];
$password = $_POST['password'];
$stmt = $bdd->prepare("SELECT * FROM users WHERE email = :email");
$stmt->execute(array('email'=>$email));
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
if(count($results)) //if record found
{
exit("Email already Exist");
}
$req = $bdd->prepare("INSERT INTO users(email,password) VALUES (:email,:password)");
$req->execute(array('email'=>$_POST['email'],'password'=>$_POST['password']));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.