好的,我很困惑。我有一些代码在数据库表中搜索用户名,然后使用if else语句运行一些代码,具体取决于是否找到用户。我的代码如下。问题是代码甚至没有看到if else语句,我不知道为什么。任何帮助表示赞赏。
$sqluser = "select * from users where username='" . $user ."'"; //Searching to see if the user is in the database
echo $sqluser . "<br><br>"; //writes out the select statement to make sure it is correct
$query = mssql_query($sqluser); //returns the results
$num_rows = mssql_num_rows($query); //gets the number of rows returned
echo $num_rows; //writes out the number of rows
if ($num_rows==0) //determines what happens next if the user exists or not
{
//displays an error box if the user doesn't exist
echo "<script type=text/javascript>";
echo "alert('That user doesn't exist. Please try again.')";
echo "</script>";
}
else
{
//will be code to run if the user does exist
echo "<script type=text/javascript>alert('Testing.')</script>";
}
答案 0 :(得分:0)
我无法添加评论。所以我会把它写成答案。
由于您声明警报JavaScript正在页面源中显示,这意味着PHP中的IF / ELSE语句正常工作。问题在于单引号。单引号警报功能中有一个引号。因此,无法执行JavaScript警报功能。
echo "alert('That user doesn't exist. Please try again.')";
尝试使用此代替
echo "alert('That user doesn\'t exist. Please try again.');";