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.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
Hi I have a field which is supposed to display 1 of 3 icons based on a 2 conditions.
The key field here is VisitPlanRequired, if the answer to this is a "No" then the the icon should be na.png, however if it a "Yes", it then depends on another variable.
So if VisitPlanRequired = yes, then the two options are either ok.jpg or notok.jpg, the actual decider is whether the field VisitPlanIssued is null or contains a date, so if it contains a date, it should go to "ok", if it doesnt, it should go to notok.
This is the code I have so far, but I am struggling to get it to work for all three conditions, I would appreciate your help:
if ($data["VisitPlanRequired"]==='No')
$value="<img src=images/na.png id='image'>";
elseif
($data["AuditPlanIssued"])
{ $value="<img src=images/ok.jpg id='image'>";}
else
$value="<img src=images/notok.jpg id='image'>";
Something like this (really the basics of programming actually...
if ($data["VisitPlanRequired"] == 'No'){
$value="<img src=images/na.png id='image'>";
}else{
if( !empty($data["AuditPlanIssued"]) ){
$value="<img src=images/ok.jpg id='image'>";
}else{
$value="<img src=images/notok.jpg id='image'>";
}
}
Success
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 7 years ago.
Improve this question
I am a beginner in php , and i want make a test with GET .
I want display , for example "ok" on my php page if my id parameter is 1 but i have always 1 when i change the id parameter to another value .
Details :
when i make this url :
http://localhost:81/test/testajax.php?id=2
expected result :
not ok
obtained result :
ok
testajax.php
<?php
if($_GET["id"] = 1)
{
die('ok');
}
else
{
die('not ok');
}
?>
One equal sign (=) sets the value of a variable. $foo = "bar"; would set $foo to store bar.
You want to use two equal signs (==), which is a comparison operator. ($foo == "bar") would check to see if $foo is equal to bar.
You can check the different types of operators at http://php.net/manual/en/language.operators.php
May be you should go through this basics before you start.
you should put two equal signs to compare.
if($_GET["id"]==1)
correct code:
<?php
if($_GET["id"] == 1)
{
die('ok');
}
else
{
die('not ok');
}
?>
As you are setting the variable, the if statement is always equating to true
Just thought it was worth Noting this as that is the logical reason for your issue
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I need to access the input value of a dynamic variable based on another input field.
Sample code:
$upid=$_GET['upid'];
$check_box_name='c'.$upid;
echo $upid;
$check=$_GET[$check_box_name];
any idea how do i access it??...Please help
The code you entered should work, but, it is vulnerable to errors, as you are dealing with a user input, you should either do a validation or a failover value.
If you are using PHP5.3+, you can easily do this as follows:
if ($check = #$_GET['c' . (#$_GET['upid'])]? : false !== false) {
//do something with $check
} else {
//failed
}
The # sign is used to omit any error or exception from being thrown. Also, it maybe a good thing to escape the $check variable for more security.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
Here's the code I'm using:
if (filter_var($desired_username, FILTER_VALIDATE_EMAIL) || ((strlen($desired_username)) > 32)) {
$usernamevalidate=FALSE;
} else {
$usernamevalidate=TRUE;
}
strlen is working perfectly, but either filter_var or FILTER_VALIDATE_EMAIL is not. Don't let the variable name trick you, "$desired_username" links to a field for an email, but it's just not working.
I can enter "test" instead of "test#test.com" or even "test#test" and it still validates. I've also tried preg_match and other methods, but none of them are validating properly.
Any help would be appreciated.
Several things:
You seem to be mixing up username and e-mail. Many e-mails are longer than 32 characters.
You've got how filter_var works backwards. A valid e-mail is going to set $usernamevalidate=FALSE with your code.
You should be doing this instead:
if(filter_var($desired_username, FILTER_VALIDATE_EMAIL)) {
$usernamevalidate=TRUE;
} else {
$usernamevalidate=FALSE;
}
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";