5 Replies - 279 Views - Last Post: 01 February 2013 - 03:38 PM Rate Topic: -----

#1 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-November 12

Parse Error

Posted 01 February 2013 - 03:26 PM

I get this error in my PHP script:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Any help is appreciated.

Here is the code:

	<?php
		if (isset($_POST['f_name']) && (isset($_POST['l_name'])))
		{
			$Fname = addslashes($_POST['f_name']);
			$Lname = addslahses($_POST['l_name']);
			$Age = addslashes($_POST['age']);
			$Avg = addslashes($_POST['avg']);
			$NewBowler = "$Lname, $Fname, $Age, $Avg\n";
			$BowlerFile = "Bowler.txt";
				
				if (file_put_contents($BowlerFile, $NewBowler, FILE_APPEND) > 0)
					echo "<p>stripslashes($_POST['f_name']) + stripslahses($_POST['l_name']) 'Has been registered to the league!'</p>\n"; //Here is the error!!
				else
					echo "<p> Registration error!</p>\n";
		else
			echo "<p>To register for the league, enter the information below and click register.</p>\n";
		}
	?>


This post has been edited by slappy5star: 01 February 2013 - 03:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Parse Error

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: Parse Error

Posted 01 February 2013 - 03:29 PM

ok, there’s a typo on line #5 and on line #12 the array needs to be put in curly braces (see also the Manual’s Array section).
Was This Post Helpful? 0
  • +
  • -

#3 slappy5star  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-November 12

Re: Parse Error

Posted 01 February 2013 - 03:33 PM

I am a little confused by your response...I am not using an array, these are variables for HTML form fields. I will browse the provided link and see if any light bulbs come one lol!
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,639
  • Joined: 12-December 12

Re: Parse Error

Posted 01 February 2013 - 03:34 PM

The way this is currently written stripslashes will be treated as a string, rather than evaluated as a function, and array variables would need to be embedded in curly brackets "Hello {$_POST['f_name']}".

However, because you need to extract the functions from the string they won't require the curly brackets.

NB The concatenation operator in PHP is a dot . not a plus sign:

echo "<p>" . stripslashes($_POST['f_name']) . stripslashes($_POST['l_name']) . "Has been registered to the league!</p>\n";


Oh, and Dormilich spotted the spelling mistake on line 5 :)

This post has been edited by andrewsw: 01 February 2013 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: Parse Error

Posted 01 February 2013 - 03:38 PM

though in this case printf() should be worth a consideration:
$html = "<p>%s %s has been registered to the league!</p>";
printf($html, stripslashes($_POST['f_name']), stripslashes($_POST['l_name']));

This post has been edited by Dormilich: 01 February 2013 - 03:38 PM

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,639
  • Joined: 12-December 12

Re: Parse Error

Posted 01 February 2013 - 03:38 PM

View Postslappy5star, on 01 February 2013 - 03:33 PM, said:

I am a little confused by your response...I am not using an array, these are variables for HTML form fields. I will browse the provided link and see if any light bulbs come one lol!

$_POST and similar are arrays.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1