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
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
I'm retrieving the postal code by using -
<?php $pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/'); ?>
It works great but if the postal code is not found, it says, "None". I can't find a way to disable the message.
You can empty the variable if the respond is None. With a simple check.
<?php
$pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/');
if($pstcde === "None")
$pstcde = ""; //Empty string. Or you can use unset($pstcde); if you want to unset the variable.
?>
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
I am trying to use the condition:
isset($_SESSION['id'])
So i just tried
echo isset($_SESSION['id']); and echo $_SESSION['id'];
But this gives output different. In fact true result gives by
echo $_SESSION['id'];
Any one have idea why this is happening?
Note: I use session_start(); at the beginning of page.
isset is used in if condition, in case you want to check if session is set or not:
<?php
if(isset($_SESSION['id'])) { // check if session named 'id' is exist
echo $_SESSION['id'];
}
?>
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 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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Ok I'm not a PHP editor by default I can do a bit but I am struggling witht his simple variable. I want to display something if the value isnt set to null. The output is run by a function i think, its a catgory for a listing so it would say something like:
WHATS ON: Music, Dance, Trance
Now if there isnt a category set it just says 'WHATS ON:' where as I dont want anything to show if there isnt a category set. Heres the output to display the 'WHATS ON' and category string:
$featured_event .= "<p class=\"complementaryInfo\"><b style=\"color:#74c1df\">WHATS ON:</b>".system_itemRelatedCategories($event->getNumber("id"), "event", true)."</p>";
and heres my variable attempt:
if (system_itemRelatedCategories($event->getNumber("id"), "event", true) == "") {
$featured_event .= "<p class=\"complementaryInfo\"><b style=\"color:#74c1df\">WHATS ON:</b>".system_itemRelatedCategories($event->getNumber("id"), "event", true)."</p>";
}
If you need any more info please ask, I hope this is enough to give you an idea of my problem.
Thanks
Your theory is almost correct. The only issue is that you are telling it to show "What's on" ONLY if there is nothing on.
Change your == to != and it should work fine. Or just drop the == "" entirely since any non-empty string will be truthy.
Personally, I'd further optimise it to:
if( $events = system_itemRelatedCategories($event->getNumber("id"),"event",true))
$featured_event .= "<p class=\"...\"><b...>WHATS ON:</b> ".$events."</p>";
This avoids calling the same function twice.
Use empty() function - if variable is not set or is empty then it returns true
if (!empty(system_itemRelatedCategories($event->getNumber("id"), "event", true)))