使用PHP显示jquery警报

时间:2015-11-04 09:45:09

标签: php jquery

您好我是PHP的新手,一切都让我很困惑。我尝试做的和失败的是在点击页面上的按钮时在屏幕上显示警告。

我的代码signInFunction.php:

<?php
if(isset($_POST['signIn'])){
    if(isset($_POST['username']) and isset($_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];

        ?>
        <script type="text/javascript">alert("test");</script>
        <?php
        echo "username is: ".$username." and password is: ". $password;
    }
    else{
        echo "Please enter username and password";
    }
}
else{
    echo "error button";
}
?>
index.php文件中的

如下所示:

  <?php include "includes/header.php" ?>
  <?php include "includes/navbar.php" ?>
  <?php include "includes/carousel.php"?> 
  <?php include "includes/marketing.php"?> 
  <?php include "includes/features.php"?>
  <?php include "includes/hidden.php"?>
  <?php include "includes/footer.php" ?>
  <?php include "includes/functions/signinFunction.php"?>

问题是我设法在底部显示数据但未能显示警告..我缺少什么?

2 个答案:

答案 0 :(得分:2)

<form action="" method="post" >
   <input name='username' type='text' value=''/>
   <input name='password' type='text' value='' />
   <input type='button' name='signIn' value='Sign In' />
</form>
<?php
if(isset($_POST['signIn'])){
    if(isset($_POST['username']) and isset($_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];

        ?>
        <script type="text/javascript">alert("test");</script>
        <?php
        echo "username is: ".$username." and password is: ". $password;
    }
    else{
        echo "Please enter username and password";
    }
}
else{
    echo "error button";
}
?>

当您点击登录按钮时,该警告应该出现

答案 1 :(得分:-1)

echo '<script language="javascript">';
echo 'alert("alert")';
echo '</script>';