Jump to content

Archived

This topic is now archived and is closed to further replies.

Mantis_61

errors errors errors

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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) [snapback]386851[/snapback][/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]

Share this post


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

Share this post


Link to post
Share on other sites
you're using the heredoc syntax and it requires that no characters exist around their delimiters, even white spaces.

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
[code]
<?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'] . '!';
}
?>
[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=386894:date=Jun 22 2006, 11:13 PM:name=Bane)--][div class=\'quotetop\']QUOTE(Bane @ Jun 22 2006, 11:13 PM) [snapback]386894[/snapback][/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
[code]
<?php
$lang['form']['invalid_entry'] = 'You entered an invalid entry in the form';
$lang['form']['no_empty'] = 'The %s field cannot be empty';
?>
[/code]

index.php
[code]
<?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');
    }
}
?>
[/code]


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 :)

Share this post


Link to post
Share on other sites

×

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.