Hi Guys,
I’ve only been learning php for a few days so i’m sorry if this is really simple but its been driving me insane for hours!
Im trying to create a basic registration form for my website. Im currently just using a really basic insert into statement so that the various fields are entered into my mysql database. However I wanted to create something a little more sophisticated and this was what i was trying to achieve;
First check that all the necessary fields have been filled in
Next check that the screen name doesn’t already exist
I want to confirm that the password and password confirmation match
Then I want to encrypt the password.
And if all that works I finally want to insert the details into the database.
This is what i’ve come up with…
[php]<?php
// Connection to database
$con = mysql_connect(“host”,“user”,“pass!”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“mydb”) or die(mysql_error());
//This code runs if the form has been submitted
if (isset($_POST[‘submit’]))
//This makes sure they did not leave any fields blank
if (!$_POST[‘screen_name’] | !$_POST[‘pass’] | !$_POST[‘pass2’] ) {
die('You did not complete all of the required fields');
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['screen_name'] = addslashes($_POST['screen_name']);
}
$usercheck = $_POST[‘screen_name’];
$check = mysql_query(“SELECT screen_name FROM login WHERE screen_name = ‘$usercheck’”)
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['screen_name'].' is already in use.');
}
//this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['screen_name'] = addslashes($_POST['screen_name']);
}
// now we insert it into the database
$insert = "INSERT INTO login (forename, surname, dob, email, screen_name, pass, pass2)
VALUES
('$_POST[forename]','$_POST[surname]','$_POST[dob]','$_POST[email]','$_POST[screen_name]','$_POST[pass]','$_POST[pass2]')";
$add_member = mysql_query($insert);
?>[/php]
When I ran a test and filled out the forms this is the error i get…
Parse error: syntax error, unexpected $end in D:\Hosting\8263933\html\bdwebsite\register2.php on line 87
Any suggestions would be greatly appreciated
Thanks!
Sam