Jump to content


Photo

errors errors errors


  • Please log in to reply
7 replies to this topic

#1 Mantis_61

Mantis_61
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 June 2006 - 03:31 PM

Will someone please show me why I keep getting 't encapsed whitespace error line 20'!!!


<?php
if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
process_form();
}else{
print_form();
}

function print_form() {
echo <<<END
<form action="$_SERVER[PHP_SELF]" method="POST">
What is your name?
<input type="text" name="name">
<input type="hidden" name="stage" value="process">
<input type="submit" value="send this on over.">
</form>
END;
}

function process_form() {
echo 'Hello' . $_POST['name'] . '!';
}
?>

Still trying to learn the language and all I ever seem to get is a steady flow of errors!


#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 22 June 2006 - 03:46 PM

Dunno, I cut and paste, and don't get the error on my server...

[!--quoteo(post=386851:date=Jun 22 2006, 11:31 AM:name=Mantis_61)--][div class=\'quotetop\']QUOTE(Mantis_61 @ Jun 22 2006, 11:31 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Will someone please show me why I keep getting 't encapsed whitespace error line 20'!!!
<?php
if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
process_form();
}else{
print_form();
}

function print_form() {
echo <<<END
<form action="$_SERVER[PHP_SELF]" method="POST">
What is your name?
<input type="text" name="name">
<input type="hidden" name="stage" value="process">
<input type="submit" value="send this on over.">
</form>
END;
}

function process_form() {
echo 'Hello' . $_POST['name'] . '!';
}
?>

Still trying to learn the language and all I ever seem to get is a steady flow of errors!
[/quote]


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 June 2006 - 03:50 PM

You sure its this code? As no errors pop up when I run it through PHP. Also your syntax is a little wrong here:
if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
it should be this:
if (isset($_POST['stage']) && ($_POST['stage'] == 'process')) {


#4 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 22 June 2006 - 04:03 PM

you're using the heredoc syntax and it requires that no characters exist around their delimiters, even white spaces.

so make sure this:
echo <<<END
and this:
END;
have NOTHING before or after them, not even a space.

#5 Mantis_61

Mantis_61
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 June 2006 - 05:03 PM

I have no idea. Tried it with the suggested tweaks and same thing. I get this error a lot when the code seems flawless. Maybe it's my server. I don't know what defaults might interfere with this though. The only option I have changed in the past was register globals and variable order. However, everything is set to defaults now. Weird other scripts run fine.

#6 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 22 June 2006 - 05:13 PM

did you try what i suggested?
also, i remembered you have to surround your _SERVER vars in curly braces.

what which line is line 20? paste your exact error here and tell us which line is line 20


try this:
<?php
if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
process_form();
}else{
print_form();
}

function print_form() {
echo <<< END
<form action="{$_SERVER['PHP_SELF']}" method="POST">
What is your name?
<input type="text" name="name">
<input type="hidden" name="stage" value="process">
<input type="submit" value="send this on over.">
</form>
END;
}

function process_form() {
echo 'Hello' . $_POST['name'] . '!';
}
?>

and remember, no characters around the [a href=\"http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc\" target=\"_blank\"]heredoc's[/a] delimiters

#7 Mantis_61

Mantis_61
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 June 2006 - 01:22 AM

I've edited my line spaces and whitespaces so the line is'nt the same every time but it points to these two every time.
I've tried the extra block around $_SERVER as well still same error.

function process_form() {
echo 'Hello' . $_POST['name'] . '!';

I don't know whats wrong?

Not trying to lose focus here but

I also have a couple other questions.

I might put in new thread. Before I repost stuff I'd like to make sure it

isn't already up here since I'm new. I'm helping to make a site that

needs to have a Chinese version. Do I actually have to learn

Chinese to do this or are there browser settings that can automatically

interpret my text strings?

I figured I could store the Chinese in variables and call them when a

browser setting is detected but how can I get the Chinese? If there is

anything on here on the subject could you direct me?

If not I'll post this up fresh. Thanks for the aid.

#8 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 24 June 2006 - 08:10 PM

[!--quoteo(post=386894:date=Jun 22 2006, 11:13 PM:name=Bane)--][div class=\'quotetop\']QUOTE(Bane @ Jun 22 2006, 11:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
what which line is line 20? paste your exact error here and tell us which line is line 20
[/quote]

better do that first ^^
or this might turn into a big waste of time :)







regarding your language problem, you would, ideally, include the appropriate language file based on the users preferences.
this language file would contain a multidimensional array with keys whose values contain the string of text in that language:

en_US.php
<?php
$lang['form']['invalid_entry'] = 'You entered an invalid entry in the form';
$lang['form']['no_empty'] = 'The %s field cannot be empty';
?>

index.php
<?php
//assume $_SESSION['language'] will hold the users language preference prefix.
// 'en_US' in this example
include $_SESSION['language'] . '.php';

if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
process_form();
}else{
print_form($lang);
}

function print_form() {
echo <<<END
<form action="{$_SERVER['PHP_SELF']}" method="POST">
What is your name?
<input type="text" name="name">
<input type="hidden" name="stage" value="process">
<input type="submit" value="send this on over.">
</form>
END;
}

function process_form($myLang) {
    if(empty($_POST['name']))
    {
        echo sprintf($myLang['form']['no_empty'], 'Name');
    }
}
?>


you would find the function [a href=\"http://www.php.net/sprintf\" target=\"_blank\"]sprintf()[/a] very useful for situations where you have to manage strings in language due to the structural differences accross different languages.



personally, i prefer using ini files with [a href=\"http://www.php.net/parse_ini_file\" target=\"_blank\"]parse_ini_file()[/a]
there's a simple trick to prevent ini files being viewable via the browser (without any Apache, chmod tricks) so if you do resort to ini files, let me know :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users