嗨,我是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"?>
问题是我设法在底部显示了数据,但未能显示警报。。我错过了什么?
<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";
}
?>
当你点击登录按钮时,该警报应该会出现
echo '<script language="javascript">';
echo 'alert("alert")';
echo '</script>';