PHP Error Message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

PHP Error Message

Post by herbie497 »

I am absolutely new to PHP so please keep answers simple :-)

I have designed and written my form, and that works perfectly,
however, I have also written a form validation code - which I copied from my PHP book

but when I uploaded to my server it came with this message:

'Parse error: parse error, unexpected $ in /home/d/p/dpierce_co_uk/we are individuals/pages/form handle.php on line 184'

I looked at my code and at 'line 184' was </html>
can someone tell me why PHP deosn't like my code?

please keep the answer simple, as I am new to this!!
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Post by panic! »

hey could you post the code (about 5 lines before and after the line with the error)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

This error is usually becuase you forgot a closing paranthesis (}) somewhere
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok here is the code as it appears at the very end -

Code: Select all

// If everything was filled out correctly
if ($first && $last && $email && $gender && $age && instruments && $town && $comments)
{
  echo "Thank you <b>$name</b>, I will reply to you at <i>$email</i>.";
  echo $message;
}
?>

</body>
</html>
'line 184' is </html>
hope this helps you help me!!

its a code to send information to me, for a band application, this end bit checks everything was filled out correctly..
but i dont know if ALL the rest of the code works because i keep getting

'Parse error: parse error, unexpected $ in /home/d/p/dpierce_co_uk/we are individuals/pages/form handle.php on line 184'

if you want i can post the WHOLE code, but i dont want to give it away!!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

The error could be anywhere in the script becuase as i said, it is becuase you have a missing closing paranthesis somewhere.

Either have a look for it yourself, or post ALL your code

Also, you missed a $ off you instruments variable
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok, i changed the $ in instruments, and i found the missing }, and put it in!

that error message has gone now (phew!)

BUT!!

when i fill out the form (testing purpose) i get

'You did not enter your First Name
You did not enter your Last Name
Your Name is $name (- I know about this I will sort it myself)
You did not enter your Email
You did not choose your Gender
You did not choose your Age
You did not choose a(n) Instrument(s)
You did not choose a town
You did not enter any Comments
If you do not want to enter Comments, enter none'

but i filled all the fields in.. help!!
I know about the '$name' variable and i can sort that myself..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

its hard for us to determine your problem without seeing your code. Sounds like a register globals problem to me though
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok i dont want to do this but..

here is the WHOLE code for the handling form

Code: Select all

<!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">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>We Are Individuals - Application Form Handle</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php
// Form Checker 2.0

// First Name
if (strlen($first) > 0)
{
  $first = stripslashes($first);
}

// If no name was entered
else
{
  $first = NULL;
	echo 'You did not enter your <b>First Name</b>';
}

// Last Name
if (strlen($last) > 0)
{
  $last = stripslashes($last);
}

// If no name was entered
else
{
  $last = NULL;
	echo 'You did not enter your <b>Last Name</b>';
}

// Name
$first = '$first';
$last = '$last';
$name = $first . ' ' . $last;
{
  echo 'Your name is <b>$name</b>';
}

// Email
if ( !(strlen($email) > 0) )
{
  $email = NULL;
	echo 'You did not enter your <b>Email</b>';
}

// Gender
if (isset($gender))
{
  if ($gender == 'M')
	{
	  $message = 'You chose <b>Male</b>';
	}
	elseif ($gender == 'F')
	{
	  $message = 'You chose <b>Female</b>';
	}
}

// If no gender was entered
else
{
  $gender = NULL;
	echo 'You did not choose your <b>Gender</b>';
}

// Age
if (strlen($age) > 0)
{
  if ($age == '16')
	{
	  $message = 'You chose <b>16</b>';
	}
	if ($age == '17')
	{
	  $message = 'You chose <b>17</b>';
	}
	if ($age == '18')
	{
	  $message = 'You chose <b>18</b>';
	}
	if ($age == '19')
	{
	  $message = 'You chose <b>19</b>';
	}
	if ($age == '20')
	{
	  $message = 'You chose <b>20</b>';
	}
}

// If no age was entered
else
{
  $age = NULL;
	echo 'You did not choose your <b>Age</b>';
}

// Instrument(s)
if (strlen($instruments) > 0)
{
  if ($instruments == 'Bass')
	{
	  $message = 'You chose <b>Bass</b>';
	}
	if ($instruments == 'Drums')
	{
	  $message = 'You chose <b>Drums</b>';
	}
	if ($instruments == 'Guitar')
	{
	  $message = 'You chose <b>Guitar</b>';
	}
	if ($instruments == 'Keyboard')
	{
	  $message = 'You chose <b>Keyboard</b>';
	}
	if ($instruments == 'Sing')
	{
	  $message = 'You chose <b>Sing</b>';
	}
}

// If no instrument(s) entered
else
{
  $instruments = NULL;
	echo 'You did not choose a(n) <b>Instrument(s)</b>';
}

// Where they live
if (strlen($town) > 0)
{
  if ($town == 'braintree')
	{
	  $message = 'You chose <b>Braintree</b>';
	}
	if ($town == 'chelmsford')
	{
	  $message = 'You chose <b>Chelmsford</b>';
	}
	if ($town == 'dunmow')
	{
	  $message = 'You chose <b>Dunmow</b>';
	}
}

// No town was entered
else
{
  echo 'You did not choose a <b>town</b>';
}

// Comments
if (strlen($comments) > 0)
{
  $comments = stripslashes($comments);
}

// If no comments were entered
else
{
  $comments = NULL;
	echo 'You did not enter any <b>Comments</b><br />';
	echo 'If you do not want to enter <b>Comments</b>, enter <i>none</i>';
}

// If everything was filled out correctly
if ($first && $last && $email && $gender && $age && $instruments && $town && $comments)
{
  echo "Thank you <b>$name</b>, I will reply to you at <i>$email</i>.";
	echo $message;
}
?>

</body>
</html>
(copyright (C) 2006 We Are Individuals)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Have you got register_globals on in your PHP.ini file?

If not, you will need to call the information like so

Code: Select all

$_GET['first'];
or

Code: Select all

$_POST['first'];
depending on your form method
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

my form method is 'post'

will I have to do that on all the variables?

first
last
gender
etc..

and where do i put that?

and what is a 'register_globals' and i dont have a php.ini file!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

herbie497 wrote:my form method is 'post'

will I have to do that on all the variables?

first
last
gender
etc..
Yes

and where do i put that?
herbie497 wrote:and what is a 'register_globals' and i dont have a php.ini file!
Yes you do - read http://uk2.php.net/register_globals

Just for your information, having register_global OFF is the prefered way of leaving your setup as it is far more secure this way
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

also look at this line:

Code: Select all

// If no name was entered
else
{
  $last = NULL;
   echo 'You did not enter your <b>Last Name</b>';
}

// Name
$first = '$first';
$last = '$last';
$name = $first . ' ' . $last;
{
  echo 'Your name is <b>$name</b>';
}
you can't do that. i don't know what you where trying to do there but that whole thing looks very strange
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok..

do i change

Code: Select all

$_POST['first'];
to

Code: Select all

$_POST['last'];
etc..

each time i put it in the code?

do i keep my original code?

Code: Select all

// First Name
if (strlen($first) > 0)
{
  $first = stripslashes($first);
}

$_POST['first'];
is that how to set it up?

where do i put

Code: Select all

$_POST['first'];
and i dont know if you think i am creating users, but its to send info from the form to me..


Re: shiznatix
i know about that i will sort it after this..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

There are 2 ways you could do this

1) Everywhere you reference a value from the for you could change it to this for example

Code: Select all

if (strlen($_POST['first']) > 0)
{
  $_POST['first'] = stripslashes($_POST['first']);
}
2) you can set all the variables at the top of the script like this

Code: Select all

$first = $_POST['first'];

if (strlen($first) > 0)
{
  $first = stripslashes($first);
}
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

herbie497 wrote:ok..

do i change

Code: Select all

$_POST['first'];
to

Code: Select all

$_POST['last'];
etc..

each time i put it in the code?
no. in your original code you are assuming that $first exists already which it doesn't. BUT! What does exist is $_POST['first']. So, you should use $_POST['first'] instead of $first (because it exists and $first does not). Likewise with all the other variables that are coming off of your form. This is all assuming you are posting the data to this page and not using get.

edit: im too late :(
Post Reply