Jump to content

Registration code still not perfectly working


SirChick

Recommended Posts

There is a few problems with my code! Firstly this error pops up when i open the page:

 

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\RegisterPage.php on line 227

 

Secondly:

 

If username already exists and error occurs and it still submits all the registration info except the username im not entirely sure why.

 

And also i had a part at the end where once registration was successful it would re-direct the user to a page, but it was redirecting before it would even load the html etc... i was unsure on how i could come around that problem.. any thoughts?

 

<?php
if (isset($_POST['RegistrationSubmission'])) {

$TermsOfService = ($_POST['TermsOfService']);
$Username = ($_Post['Username']); 
$Password = ($_POST['Password']); 
$Password2 = ($_POST['Password2']);
$Email = ($_POST['EmailRegistration']);
$Country = ($_POST['CountryChoice']);
$_SERVER = $_POST['REMOTE_ADDR'];
$Gender = $_POST['Gender'];
$jump2 = 1;
if ($Password != $Password2) {
    echo "Passwords did not match";
if ($TermsOfService == "off") {
echo "You must agree to the terms of service before registering!";
$jump2 = 0;
}
}

If ($jump2 ==1){
mysql_connect("localhost", "root", "private") or die (mysql_error());
mysql_select_db("civilian") or die (mysql_error());
$chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'");
$getUSERNAME = mysql_fetch_object($chkUSERNAME);
if($_POST['Username'] == $getUSR->Username) {
  die('Username already registered, please choose a different username!');
}
If ($Password == $Password2) {
    mysql_connect("localhost", "root", "private") or die (mysql_error());
    mysql_select_db("civilian") or die (mysql_error());
    $query = "INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) Values ('$Username', '$Password', '$Email', '$Country', '$_SERVER', '$Gender')";
    echo $query;
    mysql_query($query) or die(mysql_error());
}
}
?>

Ok thats solved the first problem :P thankyou! but the other problems with data submission still occurs.

 

 

My mistake there is a new error, this occrued upon submit being pressed this time. :

 

INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) Values ('', 'test14', '[email protected]', 'United Kingdom', '', 'Male')Duplicate entry '0' for key 1

You used

 

$_POST['Username'] == $getUSR->Username

 

which should be

 

$_POST['Username'] == $getUSERNAME->Username

 

that should solve the errors.

 

INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) Values ('', 'dave14', '[email protected]', 'United Kingdom', '', 'Male')Duplicate entry '0' for key 1

 

 

same error occurred as before.

$Username = ($_Post['Username']);

 

should be

 

$Username = $_POST['Username'];

 

$_POST is a superglobal variable (variables are case-sensitive in php)

 

Your current error is from the mysql process as you are attempting to insert another user with no username as such it is a duplicate Primary Key.

so are the other variables ok in rounded brackets? cos why would username not need rounded brackets but then the others do ?

 

cos the other variables work but not username.. i dont understand that logic lol

 

 

 

Also just to add:

 

 

When data submits it does EXCEPT username.. the field username is blank in every record in my user's table :S non others are how ever.. even when i removed the brackets. the same occured.

The rounded brackets have no reason to be there. It's  just a waste of space...

 

Also, $_SERVER = $_POST['REMOTE_ADDR'] is a very poor piece of coding. (messing around with superglobals)

 

better would be

 

$ip = $_SERVER["REMOTE_ADDR"];

 

infact non of them are inputting now :S ive changed my varibales to this:

 

$TermsOfService = $_POST['TermsOfService'];

$Username = mysql_real_escape_string($_POST['Username']);

$Password = mysql_real_escape_string($_POST['Password']);

$Password2 = mysql_real_escape_string($_POST['Password2']);

$Email = mysql_real_escape_string($_POST['EmailRegistration']);

$Country = mysql_real_escape_string($_POST['CountryChoice']);

$ip = $_SERVER["REMOTE_ADDR"];

$Gender = $_POST['Gender'];

 

 

 

someone said i needed it but its caused a nasty error on my page:

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\RegisterPage.php on line 6

 

 

im sure theres brackets missing but not sure where they go.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.