PHP JSON If or Else [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 6 years ago.
Improve this question
I'm trying to write a PHP script so if the network type is a JSON feed, I'm pulling indicates mobile event is triggered and if not another event is triggered. I can't figure out the if or else, I've tried a bunch of variations.
Code:
echo( "Network Type: " . $decoded_response['current_carrier']['network_type']);
if ($decoded_response['current_carrier']['network_type']) = 'mobile') {
echo "Event1";
} else {
echo "Event2";
}

if ($decoded_response['current_carrier']['network_type']) = 'mobile'){
maybe this should be
if ($decoded_response['current_carrier']['network_type'] == 'mobile'){
You are using single = instead of == to check for equality. = would assign and not test.

Related

Why can't I identify the false? [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 4 years ago.
Improve this question
I'm trying to fail on purpose... According to the documentation get_term_by will return false when nothing is found.
I issue:
$exiting_term = get_term_by('slug', sanitize_title("something"), 'non-existing-one');
Then I...
var_dump($existing_term);
The output from which is:
bool(false)
However, my code will not to into this block. Why is that?
if ($existing_term === false) {
/// NEVER GETS HERE.
}
You have a typo.
var_dump('exiting_term' == 'existing_term');
--> bool(false)

problem using anchor button in server(cent os) [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 4 years ago.
Improve this question
In my project i am using anchor button based on if else condition. In windows it's working perfectly.
HTML
<?php
$actionbutton = $row['status'] == 'success' ?
anchor('Users/getpdf/'.$row['appno'],'Generate Pdf') :
anchor('Users/validate/'.($row['appno']),'Pending') ;
?>
<td align="center"><?php $actionbutton;?></td>
after uploading in server (cents os) the button not displayed. how to solve this error?
On your first command, it assigns the value to your $actionbutton variable.
Your 2nd command, I think you want to echo the $actionbutton.
Maybe you want this <?=$variable?>.
So, in your case <?=$actionbutton?>
Codeigniter Documentation 👈 about alternative syntax.

Checking userlevel but it won't work [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 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']

Php help find where is syntax 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
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes===".$card['id']."") as $kat){
echo (kat['id_categories']);
}
table cols and values are all matched, something is wrong in this part of code
I tried adding $ before kat and using only one "=", sill doesnt work
NEW LINK
http://pastebin.com/RPK7vEaJ
this
where id_kartes===".$card['id']."
would be
where id_kartes=".$card['id']."
and missing $
echo $kat['id_categories'];
so full code :-
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes='".$card['id']."'") as $kat){
echo $kat['id_categories'];
}
best practice if you store your query result in a variable and loop over this variable.
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes=".$card['id']."") as $kat)

$_GET[''] not returning a value [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
$cid = $_GET['cid'];
$aid = $_GET['aid'];
echo 'test';
echo $aid;
echo $cid;
http://whatever.com/script.php?cid=40?aid=20
$cid and $aid do not echo values. Echoing is not my intended usage, I'm trying to compare $aid to a value I get from the database using $cid.
When I noticed my comparison statement validating true when it was definitely supposed to be false, I echoed out the vars and realized the statement is returning true because they are both null.
I'm completely stumped.
Your test URL should not have two question marks. Use ampersands for additional parameters after the first.
http://whatever.com/script.php?cid=40&aid=20
^

Categories