Jem's Free PHP Mail Form (Syntax Error) [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am trying to use This PHP Mail form,
http://jemsmailform.com/
and I keep getting syntax errors on 2 different lines.
Line 70, and 72.
This is what is on those lines.
if (isset($requiredFields['name']) && !empty($_POST['name']) !preg_match("/^[a- zA-Z-'\s]*$/", stripslashes($_POST['name'])))
$error_msg .= "The name field must not contain special characters.\r\n";
if (isset($requiredFields['email']) && !empty($_POST['email'] && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\#([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
$error_msg .= "That is not a valid e-mail address.\r\n";
Checking this file against a PHP syntax checker here.
http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v5-3/syntax-check.php
first it said: unexpected '!'
Then I removed the '!' and rechecked, it showed "unexpected T_BOOLEAN_AND, expecting ')'"
So I am a little lost, Not quite sure how I can configure this correctly. I dont really mind if the Name Checker doesn't work, but its the Email validator that I care about. Because you could write: "Email: Gorilla" or something and it would send to my email. So to prevent random spam and useless contact information, I would prefer the email to pass validation.
I am a bit new to PHP, so I am not quite sure where I should go from here, Any thoughts anyone?
Id appreciate the help.
Take care folks!

You missed another && in the first line and on the second if, you missed to close the ) after your empty:
if (isset($requiredFields['name']) && !empty($_POST['name']) && !preg_match("/^[a- zA-Z-'\s]*$/", stripslashes($_POST['name'])))
$error_msg .= "The name field must not contain special characters.\r\n";
if (isset($requiredFields['email']) && !empty($_POST['email']) && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\#([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
$error_msg .= "That is not a valid e-mail address.\r\n";

Related

if($_GET['info'] ==...) not checking [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I wrote a little check to display succes messages whenever a form is validated succesfully. However the check I use doesn't work. it doesn't matter what $_GET['info'] is, it just shows all messages unless $_GET['info] is empty. so even when info = loggin it shows all three messages. any help?
if(!empty($_GET['info'])){
if($_GET['info'] == "succes-paid"){
echo "<p class='succes'>De bestelling/inschrijving is succesvol verlopen.</p>";
}
if($_GET['info'] == "succes-register"){
echo "<p class='succes'>U werd succesvol geregistreerd.</p>";
}
if($_GET['info'] == "login"){
echo "<p class='succes'>U werd succesvol ingelogd.</p>";
}
}
You have a semi-colon after each of your if statements. The semi-colon means "finish the statement". Therefore your program thinks that you are done with the if and everything in your braces is treated as a block separate from your if statement. That is why those blocks are always executing.
It's because of the semicolon right after the condition of the if.
That line is actually two statements. The first is the if with condition, followed by an 'empty' statement, ended by a semi-colon. The second is a compound statement (a block of statements within a set of { .. }. The compound statement doesn't have a condition at all, so it is always executed.
if($_GET['info'] == "succes-paid") ; {echo 'x'}
condition with no statement -----^ ^ ^--------^-- compound statement without condition
\_The semi-colon that separates them.
And you have this situation three times, hence three lines of output.

preg_match() $pattern issues with format [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm looking at the preg_match instructions, but struggling to gather together what I need to only allow a certain few characters to be used, and how to implement that into the pattern format
if(preg_match('[0-9.$M]', $_POST['budget']) === true) {
$errors = 'no illegal';
} else {
//Illegal character in budget
$errors = 'illegal';
}
But I've realized that for one that doesn't work for this combination
0123456789$M. as well as that it will not function as I want it to even if I get it to work. as I need to check the $_POST['budget'] and be sure it's in the correct format before moving on with it. It can ONLY contain the characters I've put forward, anything else will create a pretty big mess.
So far, I've had javascript change any entries, but if that is disabled then they can put in whatever they please.
So I need is pseudo
if (preg_match($allowed_characters, $_POST['budget'] === true && DOESNT CONTAIN ANY OTHER CHARACTERS) {
//No illegal characters
} else {
//Illegal characters!!
}
1) preg_match returns INT or BOOL false.
2) Your pattern is not valid for preg_match
should be something like:
if(preg_match('/[^0-9\.\$M]+/', '0123456789$M.')) {
$errors = 'illegal';
} else {
$errors = 'no illegal';
}

PHP IF AND statement won't execute else section [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am trying to use an IF AND statement in PHP to test for
The submit button being pressed and
That my $testemail varable is equal to one, ie valid email in a PHP script.
If the Email is good , I get:
Thank you, 1 // ( this is correct) and email is sent
If the email is bad I get:
Thank you, 0. // ( this is not correct ) and email is still trying to be sent with bad email address.
Because the script is outputting the 0 or 1 properly, I am certain it has tested the email and correctly deciding if it is good or bad ( hence the '0' and the '1') but the script never goes to the else statement. I can't seem to get the IF AND statement right. I have tried "1" and '1'.
Very confused. Thanks in advance.
if(!filter_var($emailtmp, FILTER_VALIDATE_EMAIL))
{
$testemail = "0";
}
else
{
$testemail = "1";
}
global $testemail;
var_dump($testemail);
if (isset($_POST['submit']) && ($testemail = 1) )
{
//Everything is good, proceed
sendEmail(preg_replace(array('/<td>.*href="\?remove.*<\/td>/i', '/<th.*
<\/th>/i'), '', $_SESSION['SHOPPING_CART_HTML']));
$result_message = "Thank You. $testemail ";
}
elseif (isset($_POST['submit']))
{
//Missing Required Information
$result_message = "You must use a Valid email addresse, $testemail ";
}
($testemail = 1)
should be
($testemail === 1)
Having just ($testemail = 1) simply sets the value of testemail to 1 (which for the purposes of the if, is true since its successful). == or better yet the more exact === is what you want for checking if the left & right values match.
The problem is you are assigning the value 1 to $testemail instead of comparing it.

Parse error: syntax error, unexpected ':' in C:\wamp\www\xyz\contact-form.php on line 4 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm getting the error:
Parse error: syntax error, unexpected ':' in C:\wamp\www\xyz\contact-form.php on line 4
On a contact form that I'm trying to create for my portfolio site. I'm creating a simple check for the form submission and if it doesn't exist, it'll re-direct you back to to the index.
My code is:
if (!isset($_POST["save"]) || $_POST["save"] != ”contact”) {
header(“Location: index.php”);
exit;
}
Line 4 is the header() call, and I can't see what I've done wrong. I expect it's a small syntax error, any ideas?
The quotes aren't right, I'm assuming you copied it from a site, should be " not “
You're using funny quotes: (also known as smart quotes and curly quotes)
if (!isset($_POST["save"]) || $_POST["save"] != ”contact”) {
header(“Location: index.php”);
should be:
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {
header("Location: index.php");

PHP regex not working and keeps giving me the error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm stumbling on a regex issue and not sure why this validation gives me an error after entering in a correct string.
// City validation
if (empty($custom_fields["city_id"])) {
$response["error"] = TRUE;
$response["response"] = "City field is missing. Please try again.";
unset($_POST["s2member_pro_paypal_registration"]["nonce"]);
} elseif (!preg_match('^[a-zA-Z]+(?:[\s-]+[a-zA-Z]+)*$', $custom_fields["city_id"])) {
$response["error"] = TRUE;
$response["response"] = "Invalid City name";
unset($_POST["s2member_pro_paypal_registration"]["nonce"]);
}
I entered New York and checked the regex expression in http://gskinner.com/RegExr/. It works fine but I get an error upon submitting the input string.
Can someone please assist me?
You need to use required regex delimiter in your preg_match code as this one:
preg_match('/^[a-zA-Z]+(?:[\s-]+[a-zA-Z]+)*$/', $custom_fields["city_id"])

Categories