我有两个变量从ajax发送给php用户并通过电子邮件发送给
if ($key=="user"){
//and sql will check if user name is exist or not
if($stmt->rowCount() >0); //if user is exist
echo"user is already exist";
if(!preg_match('/^[0-9A-Za-z!@#$%][0-9A-Za-z!@#$% ]+[0-9A-Za-z!@#$%]$/',$user));
echo"bad user name";
}
如何让它发挥作用?我可能在大的if
(可能)中有更多的if
语句
使用大括号并添加更多条件,如:
if ($key=="user")
{
//and sql will check if user name is exist or not
if($stmt->rowCount() >0)
{
//if user is exist
echo"user is already exist";
if(!preg_match('/^[0-9A-Za-z!@#$%][0-9A-Za-z!@#$% ]+[0-9A-Za-z!@#$%]$/',$user))
{
echo"bad user name";
}
if(condition2)
{
//code
}
if(condition3)
{
//code
}
}
}
此外,您不需要在if语句的末尾使用分号。有关更多信息,请参阅PHP手册。