HI
I have a PHP form, that is driving me crazy. I did not compile it myself 100%. Used another form and changed it. but now, it does not want so submit.
Give me an error
Parse error: syntax error, unexpected $end in C:\Domains\3y1b.co.za\wwwroot\form.php on line 166
Can anyone please help me.
Here is the PHP code I am using
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "johanika@gmail.com";
$email_subject = "IdeaBox";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['idea'])) {
died('validation error! We are sorry, but there appears to be a problem with your idea.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$idea = $_POST['idea']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!eregi($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($idea) < 2) {
$error_message .= 'The Idea you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "idea: ".clean_string($idea)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
PHP form
Moderator: General Moderators
Re: PHP form
If code was formated, it would be more readable!
Otherwise this kind of error is caused by missing of a right curly bracket, I guess.
Try to put the right curly bracket to the end of the code.
Otherwise this kind of error is caused by missing of a right curly bracket, I guess.
Try to put the right curly bracket to the end of the code.
Re: PHP form
Just putting a brace at the end of the code would probably solve the problem. However, it assumes the entire script should be part of the unclosed block, which is not necessarily true, so this really shouldn't be your debugging tactic.
I copied your source out of the page and formatted it. This block...
...is never being closed. Put the closing brace where this block should end (in this case, it does seem to be the end of the script, before the PHP close tag).
I copied your source out of the page and formatted it. This block...
Code: Select all
if(isset($_POST['email'])) {Re: PHP form
hi
I put the bracket there but still does not work
and I do not know how the code should be placed other than copy and paste......
I really do not know PHP
I put the bracket there but still does not work
and I do not know how the code should be placed other than copy and paste......
I really do not know PHP
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP form
It's not PHP. It's just a feature of this forum, to highlight the syntax, making it more readable. You just use the PHP Code button when you're posting. Also, you should use indentation. Indentation indicates if a line is a direct child of the previous line. Here's your code, with the missing curly bracket:
Code: Select all
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "johanika@gmail.com";
$email_subject = "IdeaBox";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.\n\n";
echo $error."\n";
echo "Please go back and fix these errors.\n";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['idea'])) {
died('validation error! We are sorry, but there appears to be a problem with your idea.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$idea = $_POST['idea']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email)) {
$error_message .= "The Email Address you entered does not appear to be valid.\n";
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= "The First Name you entered does not appear to be valid.\n";
}
if(!eregi($string_exp,$last_name)) {
$error_message .= "The Last Name you entered does not appear to be valid.\n";
}
if(strlen($idea) < 2) {
$error_message .= "The Idea you entered do not appear to be valid.\n";
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "idea: ".clean_string($idea)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
?>
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP form
BTW, the whole world knows your email address now.