RedNeckRabbit93 Posted August 5, 2021 Share Posted August 5, 2021 Hello, I am currently coding a site from scratch. I know i can use templates and everything else but i want the experience. The HTML I've had down for years but it seems PHP is getting a little elusive for me. I'm trying to create a registration form and when i test my site i keep getting parse errors and syntax errors... mainly regarding the use of {} and if/else. Any help would be appreciated. Most of the code is still incomplete, I have to go back and fill in some areas I've left blank for now, but i have commented using // Where the browser is kicking back my errors. - “Any sufficiently advanced technology is indistinguishable from magic” (Arthur C. Clark, 1962) <?php $con = Mysqli_connect("'', '', ''"); if (Mysqli_connect_errno()) { echo "Failed to connect to DB. Please check your connection info." . Mysqli_connect_errno; // Only if there is an error. } //Declaring Variable for Registration form $fname = ""; $lname = ""; $em = ""; $emc = ""; $pass = ""; $passc = ""; $date = ""; $error_array = ""; if (insert($_POST['register_button'])) { // To handle the registration form // First Name Values $fname = strip_tags($_POST['reg_fname']); $fname = str_replace(' ', '', $fname); $fname = ucfirst(strtolower($fname)); // Last Name Values $lname = strip_tags($_POST['reg_lname']); $lname = str_replace(' ', '', $lname); $lname = ucfirst(strtolower($lname)); // Registration Email Values $em = strip_tags($_POST['reg_email']); $em = str_replace(' ', '', $em); // Confirm Registration Email Values $emc = strip_tags($_POST['reg_emailc']); $emc = str_replace(' ', '', $emc); // Registrsation Password Values $pass = strip_tags($_POST['reg_pass']); // Registration Password Confirmation Values $passc = strip_tags($_POST['reg_passc']); // Registration Date Values $date = date("m-d-Y"); // Here is where the browser keeps kicking back parse errors if ($em == $emc) { } else { echo "Email and Confirmation Email must match"; } if (filter_var($em, FILTER_VALIDATE_EMAIL)) { $em = filter_var($em, FILTER_VALIDATE_EMAIL) } else { echo "Invlaid Format"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/ Share on other sites More sharing options...
Barand Posted August 5, 2021 Share Posted August 5, 2021 I see two syntax errors if (insert($_POST['register_button'])) { The { has no corresponding } later in the code. if (filter_var($em, FILTER_VALIDATE_EMAIL)) { $em = filter_var($em, FILTER_VALIDATE_EMAIL) ^ } missing ; at the end of the line Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588865 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 5, 2021 Author Share Posted August 5, 2021 15 minutes ago, Barand said: I see two syntax errors if (insert($_POST['register_button'])) { The { has no corresponding } later in the code. When i put a } here the syntax error reads "Unexpected } on line blabla" if (filter_var($em, FILTER_VALIDATE_EMAIL)) { $em = filter_var($em, FILTER_VALIDATE_EMAIL) ^ } missing ; at the end of the line(Thank you for the catch!) You're right! Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588868 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 5, 2021 Author Share Posted August 5, 2021 @Barand I went ahead and for the hell of it, added the corrections to the mistakes you noticed. However now i am getting this error. Fatal error: Uncaught Error: Call to undefined function insert() in register.php:18 Stack trace: #0 {main} thrown in register.php on line 18. Line 18 references this line here: if(insert($_POST['register_button'])) { // To handle the registration form } Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588869 Share on other sites More sharing options...
Barand Posted August 5, 2021 Share Posted August 5, 2021 Make sure you have defined the function insert(). It's not a PHP function. (Or did you mean isset() ?) Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588871 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 6, 2021 Author Share Posted August 6, 2021 (edited) On 8/5/2021 at 10:50 AM, Barand said: Make sure you have defined the function insert(). It's not a PHP function. (Or did you mean isset() ?) Why did i not notice this? I am not completely new to PHP. Why in the world did I miss this function? I know better. Grrrrrr! I guess my frustration blinded me. I will fix it now. You are right, insert is not a PHP function. @Barand You were correct. This fixed my entire issue. If i had just been paying attention I wouldn't be feeling like an idiot right now! Thank you Dear Sir! Edited August 6, 2021 by RedNeckRabbit93 Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588898 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 6, 2021 Author Share Posted August 6, 2021 (edited) @Barand That fixed all the issues except for one. if (filter_var($em, FILTER_VALIDATE_EMAIL)) { $em = filter_var($em, FILTER_VALIDATE_EMAIL); else { echo "Invalid Format"; } } // This code gives me this error: Parse error: syntax error, unexpected 'else' (T_ELSE) in /*****/**/******/htdocs/site/register.php on line 60 If i do it this way: if (filter_var($em, FILTER_VALIDATE_EMAIL)) { $em = filter_var($em, FILTER_VALIDATE_EMAIL); } else { echo "Invalid Format"; } //It fixes the rror but the page is constantly returning echo "Invalid Format"; regardless of what is inputted into my form. Edited August 6, 2021 by RedNeckRabbit93 Obfuscate Directory names. Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588899 Share on other sites More sharing options...
Barand Posted August 6, 2021 Share Posted August 6, 2021 (edited) Your first one is missing a } before the else. Syntax is if (condition) { do something } else { do something else } It looks like $em is not valid. Have you tried var_dump($em) to check what's in there? PS You could just... if ( ($em = filter_var($em, FILTER_VALIDATE_EMAIL)) === false ) { echo "Invalid format"; } Edited August 6, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588900 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 7, 2021 Author Share Posted August 7, 2021 21 hours ago, Barand said: Your first one is missing a } before the else. Syntax is if (condition) { do something } else { do something else } It looks like $em is not valid. Have you tried var_dump($em) to check what's in there? PS You could just... if ( ($em = filter_var($em, FILTER_VALIDATE_EMAIL)) === false ) { echo "Invalid format"; } Yeah, it comes out as bool false. Which means I've failed to inform PHP what I'm using $em for Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588909 Share on other sites More sharing options...
RedNeckRabbit93 Posted August 7, 2021 Author Share Posted August 7, 2021 1 minute ago, RedNeckRabbit93 said: @baran Yeah, it comes out as bool false. Which means I've failed to inform PHP what I'm using $em for Quote Link to comment https://forums.phpfreaks.com/topic/313498-registration-form-php-code/#findComment-1588910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.