我使用了一个警报框,一旦将数据添加到数据库中,它应该在同一页面上弹出警报框成功消息,但它显示在不同的空白页面上,而不是在同一页面上。这是我的代码:
<?php
require("../connect.php");
error_reporting(0);
/*
if(!(adminsessioncheck()))
header('location:index.php'); */
if(isset($_POST['add']))
{
$username=$_POST['username'];
$password=$_POST['password'];
if($_POST['password'] !== $_POST['cpassword']) {
echo("Password did not match! Try again. ");
}
else {
mysql_query("INSERT INTO users VALUES('','$username','$password')") or die(mysql_error());
echo '<script type="text/javascript"> window.alert(""New user added."")</script>';
}
}
?>
<form action="" method="post" >
<table width="330" height="135" border="0" class="text">
<tr>
<td><label>User Name</label></td>
<td><input type="text" name="username" id="username" required></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input type="password" id="password" name="password" required></td>
</tr>
<tr>
<td><label>Confirm Password</label></td>
<td><input type="password" id="cpassword" name="cpassword" required></td>
</tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td><td align="center"><input type="submit" name="add" value="Add"></td></tr>
</table>
</form>