All In One Simple PHP Test Script Need Help

dquigley

New Member
Messages
249
Reaction score
0
Points
0
So I bought a PHP book that is giving me lessons to do and the one I just did was a "All in one" script" that instead of having a front end and back end script it just has it all in one file. Anyways I typed it all up and I am getting a error on line 29.
Parse error: parse error in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\allinone_form.php on line 29

Anyways here is the code

PHP:
<HTML>
<HEAD>
<TITLE>All-In-One</TITLE>
</HEAD>
<BODY>

<?

$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">

<P><strong>Your Name:</strong><br>
<INPUT type=\"text\" NAME=\"sender_name\" SIZE=30></P>

<P><strong>Your E-Mail Address:</strong><br>
<INPUT type=\"text\" NAME=\"sender_email\" SIZE=30></P>

<P><strong>Message:</strong><br>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></P>

<INPUT type=\"hidden\" name=\"op\" value=\"ds\">

<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></P>

</FORM>";

if ($_POST[op] != "ds) {
    // They need to see the form
    echo "$form_block";
} else if ($_POST[op} =="ds") {
    if ($_POST[sender_name] == "") {

$name_err = "font color=red>Please enter your name!</font><br>;
$send = "no";

if ($_POST[sender_email] == "") {
$email_err = "<font color=red>Please enter your e-mail address!</font><br>";
$send = "no";
}

if ($_POST[message] == "") {
    $message_err = "<font color red>Please enter a message!</font><br>";
    $send = "no";
}

if ($send != "no") {
    // it's ok to send!
$to = "dquigley@dollarstoriches.com";
$subject = "All-In-One Website Feedback";
$mailheaders = "From: My Web Site <dquigley@dollarstoriches.com> \n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";
$msg = "E-MAIL SENT FROM WWW SITE\n";
$msg .= "Sender's Name:   $_POST[sender_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message:        $_POST[message]\n\n";

mail($to, $subject, $msg, $mailheaders);

echo "<P>Mail has been sent!</P>";
}

else if ($send == "no") {

echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
    }
}

?>
?>

</BODY>
</HTML>


Line 29 is
PHP:
    echo "$form_block";

Thanks for the help in advance, also please try to keep the help to error correction and not changing the script, this is just for learning, and Id like to do it BY THE BOOK so please, errors only.
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Line 27 should be

if ($_POST[op] != "ds") {

You forgot the closing quote.
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
Yes thank you, I fixed that and a couple other errors that I found, now I am getting a error for line 34

$send = "no";
Edit:
Nm fixed that one, now I got error on line 75
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
well I see 2 end ?> php tags, while you only have one opening, not sure if that's the problem tho, I just saw that
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
Oops I fixed that but that didnt fix anything, thanks


Here is current script, I fixed lots of errors.

PHP:
<HTML>
<HEAD>
<TITLE>All-In-One</TITLE>
</HEAD>
<BODY>

<?

$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">

<P><strong>Your Name:</strong><br>
<INPUT type=\"text\" NAME=\"sender_name\" SIZE=30></P>

<P><strong>Your E-Mail Address:</strong><br>
<INPUT type=\"text\" NAME=\"sender_email\" SIZE=30></P>

<P><strong>Message:</strong><br>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></P>

<INPUT type=\"hidden\" name=\"op\" value=\"ds\">

<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></P>

</FORM>";

if ($_POST[op] != "ds") {
	// They need to see the form
	echo "$form_block";
} else if ($_POST[op] == "ds") {
	if ($_POST[sender_name] == "") {

$name_err = "font color=red>Please enter your name!</font><br>";
$send = "no";

if ($_POST[sender_email] == "") {
$email_err = "<font color=red>Please enter your e-mail address!</font><br>";
$send = "no";
}

if ($_POST[message] == "") {
	$message_err = "<font color red>Please enter a message!</font><br>";
	$send = "no";
}

if ($send != "no") {
	// it's ok to send!
$to = "dquigley@dollarstoriches.com";
$subject = "All-In-One Website Feedback";
$mailheaders = "From: My Web Site <dquigley@dollarstoriches.com> \n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";
$msg = "E-MAIL SENT FROM WWW SITE\n";
$msg .= "Sender's Name:   $_POST[sender_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message:  	  $_POST[message]\n\n";

mail($to, $subject, $msg, $mailheaders);

echo "<P>Mail has been sent!</P>";
}

else if ($send == "no") {

echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
	}
}

?>

</BODY>
</HTML>
 
Last edited:

dquigley

New Member
Messages
249
Reaction score
0
Points
0
hmm could u be a bit more specific as where to put what, I tried to fix it with what u said and I think I did it wrong, thank you
Edit:
Ahh nm I fixed it thank you for ur help it works now u were all great.
 
Last edited:

TheMan177

New Member
Messages
179
Reaction score
0
Points
0
If you are having difficulty in identifing where brackets open and close, might I suggest a change to your indent style. Here's an example of what I'm talking about:

PHP:
<HTML>
    <HEAD>
        <TITLE>All-In-One</TITLE>
    </HEAD>
    <BODY>
<?

$form_block = " 
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\"> 

<P><strong>Your Name:</strong><br> 
<INPUT type=\"text\" NAME=\"sender_name\" SIZE=30></P> 

<P><strong>Your E-Mail Address:</strong><br> 
<INPUT type=\"text\" NAME=\"sender_email\" SIZE=30></P> 

<P><strong>Message:</strong><br> 
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></P> 

<INPUT type=\"hidden\" name=\"op\" value=\"ds\"> 

<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></P> 

</FORM>";

if ($_POST[op] != "ds")
{
    // They need to see the form
    echo "$form_block";
}
else if ($_POST[op] == "ds")
{
    if ($_POST[sender_name] == "")
    {
        $name_err = "font color=red>Please enter your name!</font><br>";
        $send = "no";

        if ($_POST[sender_email] == "")
        {
            $email_err = "<font color=red>Please enter your e-mail address!</font><br>";
            $send = "no";
        }

        if ($_POST[message] == "")
        {
            $message_err = "<font color red>Please enter a message!</font><br>";
            $send = "no";
        }

        if ($send != "no")
        {
            // it's ok to send!
            $to = "dquigley@dollarstoriches.com";
            $subject = "All-In-One Website Feedback";
            $mailheaders = "From: My Web Site <dquigley@dollarstoriches.com> \n";
            $mailheaders .= "Reply-To: $_POST[sender_email]\n";
            $msg = "E-MAIL SENT FROM WWW SITE\n";
            $msg .= "Sender's Name:   $_POST[sender_name]\n";
            $msg .= "Sender's E-Mail: $_POST[sender_email]\n";
            $msg .= "Message:        $_POST[message]\n\n";

            mail($to, $subject, $msg, $mailheaders);

            echo "<P>Mail has been sent!</P>";
        }
        else if ($send == "no")
        {
            echo "$name_err";
            echo "$email_err";
            echo "$message_err";
            echo "$form_block";
        }
    }
}
?>
    </BODY>
</HTML>

The opening and closing brackets always exist on the same indentation as one another, might help you identify problems like this a bit more.
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
Ahh yes, I like that, I will try and do that from now on thank you again.
 
Top