Hi guys; I'm pretty new to PHP and im currently taking my A levels, for my project I am making a website that uses a server side log in system which allows users to access there account, sure this shouldn't be too hard for many of you to debug!
Here's the code I have presently
<?php
//Execute the the following script once "submit" button is pressed
if(isset($_POST['submit']));
// Include the connection.php file
include('scripts/connection.php');
//List of variables that are assigned against the Register.php
{
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$dob = $_POST['dob'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$contact = $_POST['contact'];
//Else statement to force a valid e-mail syntax to be inputted
//Echo statemment outputs error message to browser
if(!filter_var($email,FILTER_VALIDATE_EMAIL) || !filter_var($email2,FILTER_VALIDATE_EMAIL))
{
echo 'A valid E-mail is required.';
}
//Statement to say if Contact is not equal to numeric string then present error.
elseif(!empty($contact))
{
if(!is_numeric($contact))
{
echo 'Enter a valid Contact No.';
}
}
if($password != $password2)
{
echo "Passwords do not match!";
}
elseif($email != $email2)
{
echo 'Emails do not match!';
}
// statement to distinguish if the named fields are populated.
// echo statemement is the output if the value is false for any of the variable $
elseif
(empty($username) || empty($password) || empty($password2) || empty($firstname) || empty($lastname) || empty($dob) || empty($address) || empty($town) || empty($county) || empty($postcode))
{
echo ' All fields marked with an * are required';
}
else
{
$password = md5($password);
$sql = mysql_query("INSERT INTO users(username,password,email,firstname,lastname,dob,address1,address2,town,county,postcode,contact,time)
VALUES('$username','$password','$email','$firstname','$lastname','$dob','$address1','$address2','$town','$county','$postcode','$contact', now())") or die(mysql_error());
if($sql)
{
echo 'Successfully submitted, you may now login';
}
}
}
?>
I can also place in the included files if needed in future, register.php is merely a HTML form built up in <P> blocks and the other two files are the SQL connection file and CSS sheet.
When I run this from my WAMP server I receive an "undefined Index" error and then below my form is still presented, now I know undefined Index normally means that the variable hasnt been defined? but whats confusing me is the fact that previosly whilst developing this code, this error did not appear.
Any help would be greatly appreciated
Thanks
Alex.