Checking userlevel but it won't work [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 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']

Related

Php Or operator doesn´works propertly [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 11 months ago.
Improve this question
I´m trying to use or operator in a php sentence but only validate the first condition, what´s wrong?
if ($_SESSION['user_id'] != 4 || $_SESSION['rol'] != 1)
{
//exit
}else{
//do something
}```
You should invert the condition in this way:
if ($_SESSION['user_id'] == 4 || $_SESSION['rol'] == 1)
//it's ok
else
//exit
Because otherwise if the user_id is 4 it will otherwise fail if it doesn't have the role expected

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)

PHP JSON If or Else [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 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.

Is IF obligatory to be followed by ELSE [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 7 years ago.
Improve this question
I am not sure if the IF must be followed by ELSE like in my example above or if IF can be used alone like it is without any ELSE.
Will the page show to anyone if there is no ELSE? I am a beginner...
<?php
$rank = $user["rank"];
if ($rank != 'ADMIN'){
header('Location: get_the_he.._out.php');
exit();
}
else {
?>
<html>
<head><title>Show Page</title></head>
<body>
Here we show page if user is admin
</body>
</html>
<?php } ?>
NO. There is no need to have an ELSE with an IF. However you then need to make sure that the script will not continue after the IF, as you are doing here :)

$_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