如何向此pdo腳本添加電子郵件驗證。用戶在'textfield'中輸入他們的電子郵件地址。只是,如果輸入的電子郵件地址是不是我想要的數據庫,它重定向到fail.html如何在php腳本上驗證電子郵件地址
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="orders"; // Table name
$email = $_POST['textfield'];
$db = new PDO('mysql:host='.$host.
';dbname='.$db_name.
';charset=UTF-8',
$username, $password);
$stmt = $db->prepare('SELECT * FROM `orders` WHERE `email`=:email LIMIT 1');
$stmt->bindValue(':email', $email, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo "The is: ".$result['name'].", and mail is: ".$result['email']." . Status: ".$result['status'];
?>
[使用正則表達式驗證電子郵件地址]可能的重複(http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – 2013-04-30 16:21:26
rowCount會告訴你它是否存在http://php.net/manual/en/pdostatement.rowcount.php – Waygood 2013-04-30 16:22:29
添加if-else條件... – raidenace 2013-04-30 16:22:33