dsonesuk Posted April 22, 2016 Share Posted April 22, 2016 Beginners mistake again! here's a clue, always check syntax on previous line from the line listed in error. 1 Link to comment Share on other sites More sharing options...
Truman Posted April 22, 2016 Author Share Posted April 22, 2016 (edited) Ok, I see it> $_POST['last_name]; I forgot a single quotation mark after last_name. And I also spotted a mistake in line 14. Now everything is fine. I will do my best to try to figure out these beginners mistakes before I post here. Edited April 22, 2016 by Truman Link to comment Share on other sites More sharing options...
Truman Posted April 27, 2016 Author Share Posted April 27, 2016 An another problem, php code checker see no mistake: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Registration</title> <style type="text/css" media="screen"> .error { color: red;} </style> </head> <body> <h1>Registration Results</h1> <?php // Script 6.2 handle_reg.php $okay = TRUE; if (empty($_POST['email'])) { print '<p class="error">Please enter your email address.</p>'; $okay = FALSE; } if (empty($_POST['password'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if (empty($_POST['confirm'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if ($_POST['password'] != $_POST['confirm']) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = FALSE; } if (is_numeric($_POST['year'])) { $age = 2016 - $_POST['year']; } else { print '<p>Please enter the year you were born as four digits.</p>'; $okay = FALSE; } if ($_POST['year'] >= 2016) { print '<p class="error">Either you enter your birth year wrong or you come from the future!</p>'; $okay = FALSE; } if ($okay) { print '<p>You have been successfully registered.</p>'; print '<p>You will turn $age this year</p>'; } ?> </body> </html> and I receive: Registration ResultsYou have been successfully registered. You will turn $age this year I don't understand why it doesn't show $age variable, the formula should be OK. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 27, 2016 Share Posted April 27, 2016 When using print with variable within string use double quotes, else it will print as string, else you escape string from php like print '<p>You will turn '.$age.' this year</p>';Note: second time i have done this! major problem with forum multiple 'oops error' message with 'server to busy' WHAT IS HAPPENING? 1 Link to comment Share on other sites More sharing options...
Truman Posted April 27, 2016 Author Share Posted April 27, 2016 I used double quotes, it works great. Thank you. Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 Again a thing I don't understand, I'm working on nesting conditionals: <?php // Script 6.2 handle_reg.php $okay = TRUE; if (empty($_POST['email'])) { print '<p class="error">Please enter your email address.</p>'; $okay = FALSE; } if (empty($_POST['password'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if (empty($_POST['confirm'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if ($_POST['password'] != $_POST['confirm']) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = FALSE; } if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { if ($_POST['year'] < 2015) { $age = 2015 - $_POST['year']; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } } else { print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = FALSE; } if (!isset($_POST['terms']) AND ($_POST['terms'] == 'YES') ) { print '<p class="error">You must accept the terms.</p>'; $okay = FALSE; } if ($okay) { print '<p>You have been successfully registered.</p>'; print "<p>You will turn $age this year</p>"; } ?> it says: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\handle_reg.php on line 32 line 32 is: if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { Why is opening curly brace unexpected? Link to comment Share on other sites More sharing options...
Ingolme Posted April 28, 2016 Share Posted April 28, 2016 You have mismatched parentheses. if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { I don't think "AND" is a valid keyword in PHP. You should use &&. Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 (edited) I receive the same message after eding the parenthesis, that '{' is unexpected... Edited April 28, 2016 by Truman Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 I fixed the previos problem but now the message is: - Please enter the year you were born as four digits. ...and I entered 4 digits. Any idea why this conditional doesn't work? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 28, 2016 Share Posted April 28, 2016 '==4' should be outside the parenthesis for string length function. 1 Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 And now again I receive that '{' is unexpected. I don't understand what is wrong with this curly brace...It's not about parenthesis now... Link to comment Share on other sites More sharing options...
Ingolme Posted April 28, 2016 Share Posted April 28, 2016 The issue is that every single opening parenthesis needs to have a closing parenthesis before the curly brace. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 28, 2016 Share Posted April 28, 2016 if ( is_numeric($_POST['year']) AND (strlen($_POST['year'] == 4) ) { should be if ( is_numeric($_POST['year']) && (strlen($_POST['year'] ) == 4)) { You can use 'AND' but! it uses a more complicated method of parenthesis to give it higher precedence, because its precedence is lower than other operators compared to using '&&' so you have to make allowance for that. Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 After copypaste of your code I receive the same message. If you want I can attach html and php code that you can see it yourself. Link to comment Share on other sites More sharing options...
Ingolme Posted April 28, 2016 Share Posted April 28, 2016 Just copy the few lines of code that the issue is on and post it here. Link to comment Share on other sites More sharing options...
Truman Posted April 28, 2016 Author Share Posted April 28, 2016 if ( is_numeric($_POST['year']) && (strlen($_POST['year'] ) == 4)) { if ($_POST['year'] < 2015) { $age = 2015 - $_POST['year']; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } } else { print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = FALSE; } Link to comment Share on other sites More sharing options...
Ingolme Posted April 28, 2016 Share Posted April 28, 2016 Are you sure that the error is pointing to those lines of code? The problem must be somewhere else in your document. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 28, 2016 Share Posted April 28, 2016 compare with this <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Registration</title> <style type="text/css" media="screen"> .error { color: red;} </style> </head> <body> <h1>Registration Results</h1> <?php // Script 6.2 handle_reg.php // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX below is for testing only $_POST['email'] = "bull@.com"; $_POST['password'] = "bull"; $_POST['confirm'] = "bull"; $_POST['year'] = 2010; $_POST['terms'] = 'YES'; // XXXXXX end testing code $current_year = date("Y"); //added by dsonesuk $okay = TRUE; if (empty($_POST['email'])) { print '<p class="error">Please enter your email address.</p>'; $okay = FALSE; } if (empty($_POST['password'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if (empty($_POST['confirm'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } if ($_POST['password'] != $_POST['confirm']) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = FALSE; } if (is_numeric($_POST['year']) && (strlen($_POST['year']) == 4 )) { if ($_POST['year'] < $current_year) { $age = $current_year - $_POST['year']; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } } else { print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = FALSE; } if (!isset($_POST['terms']) && ($_POST['terms'] !== 'YES')) { //should be NOT Equal print '<p class="error">You must accept the terms.</p>'; $okay = FALSE; } if ($okay) { print '<p>You have been successfully registered.</p>'; print "<p>You will turn $age this year</p>"; } ?> </body> </html> Link to comment Share on other sites More sharing options...
Truman Posted April 29, 2016 Author Share Posted April 29, 2016 And again:Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\handle_reg.php on line 33 Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2016 Share Posted April 29, 2016 Are you sure its not a cache problem again? Link to comment Share on other sites More sharing options...
Truman Posted April 29, 2016 Author Share Posted April 29, 2016 I added '?wellthisis=bull' and receive the same message. Link to comment Share on other sites More sharing options...
Ingolme Posted April 29, 2016 Share Posted April 29, 2016 You might as well attach the whole document so we can look through it. Make sure it's the most recent version. Link to comment Share on other sites More sharing options...
Truman Posted April 29, 2016 Author Share Posted April 29, 2016 OK. handle_reg.php Link to comment Share on other sites More sharing options...
Ingolme Posted April 29, 2016 Share Posted April 29, 2016 The file you've attached works without error when I tested it. There might be some strange server-side caching going on in your server. Try renaming the file and running it. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2016 Share Posted April 29, 2016 I added '?wellthisis=bull' and receive the same message. You have to change it every time, else it will load the older page with that querystring again! ?wellthisis=bull1 ?wellthisis=bull2 or you could code querystring value to be timestamp so it will be different everytime from submitted form. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now