boblan66 Posted October 27, 2010 Share Posted October 27, 2010 I'm new to php and having some trouble with debugging a piece of code. Could someone please help me understand what's the error. I'm using Code Lobster for debugging and attempting to validate input for a simple sign in form. The error is and code is shown below. If I can understand this, I think I can continue with the rest of the checking. Parse error: syntax error, unexpected T_FOREACH, expecting ')' in C:\wamp\www\login_check_blank.php on line 20 <php // Program name - login_check_Blank.php // Description - checks form for blank fields // Date - 10/26/10 // Programer - R. Langevin ?> <html> <head> <title>Checking for empty fields</title> </head> <body> <?php // set up array for all fields $labels = array( "userName" => "username", "passWord" => "password", // Check each field for blanks foreach ($_POST as $field => $value) { } if ($value =="") { $blank_array[] = $field; } // end of foreach loop for $_post // if any fields were blank, display error message and redisplay form if (@sizeof ($blank_array) >0 { echo "<strong>One or more requied fields were found to be blank</strong>" // display list of blank fields foreach($blank_array as $value) { echo " $nbsp; {$labels[$value] } <br>"; } } echo "$userName "welcome back to the Taft Union High School class of 65 website." exit() ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/ Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 You left the parenthesis open and didn't terminate the line with a semicolon after you define the array above it. Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1126932 Share on other sites More sharing options...
boblan66 Posted October 27, 2010 Author Share Posted October 27, 2010 Sorry if you get this twice, but my system hick cupped. First, thanks for the help. I went through the code reformatted it and corrected more errors. However, I still get an error at line 37. (thats right after the closing ?>. The error is given below. Parse error: syntax error, unexpected $end in C:\wamp\www\login_check_blank.php on line 37 Here is a corrected copy of my code: <php // Program name - login_check_Blank.php // Description - checks form for blank fields // Date - 10/26/10 // Programer - R. Langevin ?> <html> <head> <title>Checking for empty fields</title> </head> <body> <?php // set up array for all fields $labels = array( "userName" => "username", "passWord" => "password"); // Check each field for blanks foreach($_POST as $field => $value){ if ($value ==""){ $blank_array[] = $field;} // if any fields were blank, display error message if (@sizeof($blank_array) >0) { echo "<b>One or more requied fields were found to be blank</b>"; // display list of blank fields foreach($blank_array as $value) { echo " $nbsp;{$labels[$value]}<br>"; } } echo " $userName, welcome back to the Taft Union High School class of 65 website." ?> (this is line 37) </body> </html> Which brings me to the next question. How do you normally end and go back to the calling page or any other desired page? Thanks in advanced for your help. Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1126968 Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 That error nearly always indicates a missing closing curly brace somewhere in the code. Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1126969 Share on other sites More sharing options...
boblan66 Posted October 27, 2010 Author Share Posted October 27, 2010 Thanks I found it. That's an important thing to remember. Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1127119 Share on other sites More sharing options...
mannyee Posted October 27, 2010 Share Posted October 27, 2010 Quote hich brings me to the next question. How do you normally end and go back to the calling page or any other desired page? well, you use the header function like header('Location: path/to/desired/page.php'); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1127141 Share on other sites More sharing options...
boblan66 Posted October 28, 2010 Author Share Posted October 28, 2010 Thank you very much for your reply. Really appreciate the assistance. BobLan66 Quote Link to comment https://forums.phpfreaks.com/topic/216954-having-trouble-debugging/#findComment-1127405 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.