hi, i have created a simple page in php to add users to a database. you can enter all the details, i.e. first name, surname, username etc, but when submitted it adds two user records to database instead of just one. its something simple is it possibel for anyone to help? here are the two scripts
file name: addform.php
<?php
##Register Student
echo "<h1> StudentRegister </h1>";
echo "<form method = 'Post' action='addstudent.php' >";
echo "<p><b>First Name:</b> <input type='text' name='first_name' size='15' maxlength='15' value='' /></p>";
echo "<p><b>Last Name:</b> <input type='text' name='surname' size='30' maxlength='30' value='' /></p>";
echo "<p><b>User Name:</b> <input type='text' name='username' size='10' maxlength='20' value=' ' /></p>";
echo "<p><b>Password:</b> <input type='password' name='password1' size='20' maxlength='20' /> <small></p>";
echo "<p><b>Confirm Password:</b> <input type='password' name='password2' size='20' maxlength='20' /></p>";
//echo "</fieldset>";
echo "<div align='center'><input type='submit' name='submit' value='Register' /></div>";
?>
filename : addstudent.php
<?php
##ADD STUDENT
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("cybercbt") or die(mysql_error());
$Firstname=$_POST['first_name'];
$Surname=$_POST['surname'];
$Username=$_POST['username'];
$Password1=$_POST['password1'];
$Password2=$_POST['password2'];
IF ((!$Firstname) || (!$Surname) || (!$Username) || (!$Password1) || (!$Password2))
{
Echo "Please Enter Values Into All fields";
}
ELSE IF ($Password1!=$Password2)
{
echo "Passwords Dont Match!!!";
exit();
}
$query = "INSERT INTO student(first_name, surname, username, password) VALUES ('$Firstname', '$Surname', '$Username', '$Password1')";
$result = @mysql_query($query); // Run the query
$result=mysql_query($query) or die(mysql_error());
IF (!$result)
{
echo "There has been a problem updating this record";
}
ELSE
{
echo "<br>";
ECHO "<CENTER>";
echo "<H1>Record Updated Successfully<H1>";
ECHO "</CENTER>";
}
?>