一个脚本的echo函数下的警报在php中不起作用?

时间:2014-02-13 12:55:55

标签: javascript php mysql

下面的编码,包括这个程序中的两个函数,一个函数将经销商插入数据库“insert_dealer”,之前一个函数检查特定的经销商是否已经创建了一个帐户,为此,我使用了函数“check_email” ”

现在我的问题是

echo "<script>
alert('Username already exist');
 </script>" 

在check_user函数警报工作下, 之后将经销商插入db,其中

echo "<script>
 alert('Dealer's profile has been added. Login credentials are sent to their mail id.');
</script> 

警报不起作用

将新的经销商添加到数据库中,但不显示任何警告。

请检查以下代码并提出您的想法。

<?
include_once('config.php');

function insert_dealer($title, $fname, $lname, $email, $phone, $token)
{
mysql_query("SET NAMES utf8");  
{   $user_query = "INSERT INTO dealer_tbl(title, firstname, lastname, email, phone, password, date_created, time_created) 
          VALUES ('$title','$fname','$lname','$email','$phone',password('$token'), CURDATE(), CURTIME())";
}
$user_result = mysql_query($user_query);
// echo $user_query;
if (!$user_result) 
{
    die('Error on query: ' . mysql_error());

}
else    
{   
    echo "<script>
    alert('Dealer's profile has been added. Login credentials are sent to their mail id.');
    window.location = './dealer_portal.php'</script>";
    /*header('Location: dealer_portal.php?status=1&uname='.$email.'&pwd='.$token);*/

}   
}

function check_email($title, $fname, $lname, $email, $phone, $token)
{
mysql_query("SET NAMES utf8");  
{   $dealer_query = "SELECT * FROM `dealer_tbl` WHERE `email` = '". $email ."'";
}
$result = mysql_query($dealer_query);
$num_rows = mysql_num_rows($result);
// echo $user_query;
if ($num_rows > 0) 
{
    echo "<script>
    alert('Username already exist');
    window.location = './dealer_portal.php'</script>";

    return 0;
}else{
insert_dealer($title, $fname, $lname, $email, $phone, $token);
return 1;

}   
}
?>

2 个答案:

答案 0 :(得分:1)

对于警报不起作用的情况,您有一个JavaScript错误。您的文本中的单引号需要进行转义,或者您的字符串应该用双引号括起来。

echo "<script>
alert('Dealer\'s profile has been added. Login credentials are sent to their mail id.');
window.location = './dealer_portal.php'</script>";

答案 1 :(得分:0)

行情存在问题,尝试这样的事情:

echo "<script>
    alert('Dealer\'s profile has been added. Login credentials are sent to their mail id.');
    </script>";

否则你需要连接你的字符串&amp;变量