Jump to content

Having trouble debugging


boblan66

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.