SirChick Posted July 31, 2007 Share Posted July 31, 2007 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()); } } ?> Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/ Share on other sites More sharing options...
lightningstrike Posted July 31, 2007 Share Posted July 31, 2007 I believe you need an additional } bracket at the end of your code provided. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311929 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 Ok thats solved the first problem 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 Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311934 Share on other sites More sharing options...
lightningstrike Posted July 31, 2007 Share Posted July 31, 2007 You used $_POST['Username'] == $getUSR->Username which should be $_POST['Username'] == $getUSERNAME->Username that should solve the errors. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311936 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 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. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311938 Share on other sites More sharing options...
lightningstrike Posted July 31, 2007 Share Posted July 31, 2007 $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. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311941 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 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. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311945 Share on other sites More sharing options...
lightningstrike Posted July 31, 2007 Share Posted July 31, 2007 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"]; Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311948 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 so $_SERVER will be auto regocnised without it being declared firstly? Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311953 Share on other sites More sharing options...
lightningstrike Posted July 31, 2007 Share Posted July 31, 2007 Yes. $_SERVER is a php SUPERGLOBAL variable. Which is pre-defined based on data automatically gathered by php from the user. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311956 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 Ok i done it but it didnt work.. it did input something in my Ip filled "Array". Which i duno if thats suppose to happen ? But also username is still not being inputted :S Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-311958 Share on other sites More sharing options...
SirChick Posted July 31, 2007 Author Share Posted July 31, 2007 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. Link to comment https://forums.phpfreaks.com/topic/62678-registration-code-still-not-perfectly-working/#findComment-312000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.