Here is my php file, I'm inserting the data into Database successfully, once the add button is clicked the data is inserted and an alert message is shown "New user added" on insert but the problem is that after the data is inserted and each time i click reload page it inserts the previous data to the database and displays the message "New user added".
I'm trying to insert to the database and once its inserted it should show the alert message "New user added" and clear all the text boxes. this is what i'm trying to do.
<?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.onload = function(){
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>