(“如何检查php中是否已经存在用户名和电子邮件。以下是我正在使用的内容-我已经编辑了我的帖子。对此是否有任何更正,请告诉我。”
<?php
include("config.php");
session_start();
$error="";
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$message = $_POST['message'];
date_default_timezone_set('Asia/Kolkata');
$date=date("d/m/Y h:i:sa");
if(!$error) {
$sql="select * from request where (first='$first' or
email='$email');";
$res=mysqli_query($db,$sql);
if (mysqli_num_rows($res) > 0) {
// output data of each row
$row = mysqli_fetch_assoc($res);
if ($first==$row['first'])
{
echo "Username already exists";
}
elseif($email==$row['email'])
{
echo "Email already exists";
}
exit();
}
else
{
$sql = "INSERT INTO request (first,last,email,message,dt)
VALUES('$first','$last','$email','$message','$date')";
if (mysqli_query($db, $sql)) {
echo "Request sent Sucessfully";
header ("Location: thankyou.html");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($db);
}
mysqli_close($db);
mysql_close($db);
?>
我收到此错误消息-无法访问此网站。
任何帮助都很好
答案 0 :(得分:0)
如果仅使用
,请勿使用elseif ($first==$row['first'])
{
echo "Username already exists";
}
和
if($email==$row['email'])
{
echo "Email already exists";
}
另外。或者您可以使用三元条件。