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
i want a system like this :
function check()
{
$sqlquery = mysql_query("SELECT * FROM clients WHERE id='$this->ClientID'
AND username='$this->ClientUSERNAME'") or die(mysql_error());
$showmysql = mysql_fetch_array($sqlquery );
$statusOK = $showmysql['status'];
if ($statusOK == "Active" || "1");{
return true;
}
else if ($statusOK == "Pending");{
$this->Redirect("pending.php");
}
else if ($statusOK == "Susspended");{
$this->Redirect("sus.pjp");
}
}
But When i put this codes in adobe dreamweaver i see the errors in (})... What is my problem?Please write the true code
Remove semicolon ; from if-else
if ($statusOK == "Active" || "1");{
^
else if ($statusOK == "Pending");{
^
if ($statusOK == "Active" || "1") {
else if ($statusOK == "Pending") {
Remove semicolons into your conditions like if, else if
<?php
function check()
{
$sqlquery = mysql_query("SELECT * FROM clients WHERE id='$this->ClientID'
AND username='$this->ClientUSERNAME'") or die(mysql_error());
$showmysql = mysql_fetch_array($sqlquery );
$statusOK = $showmysql['status'];
if ($statusOK == "Active" || "1")
{
return true;
}
else if ($statusOK == "Pending")
{
$this->Redirect("pending.php");
}
else if ($statusOK == "Susspended"){
$this->Redirect("sus.pjp");
}
}
?>
function check()
{
$sqlquery = mysql_query("SELECT * FROM clients WHERE id='$this->ClientID' AND username='$this->ClientUSERNAME'") or die(mysql_error());
$showmysql = mysql_fetch_array($sqlquery );
$statusOK = $showmysql['status'];
if ($statusOK == "Active" || "1") {
return true;
}
else if ($statusOK == "Pending") {
$this->Redirect("pending.php");
}
else if ($statusOK == "Susspended") {
$this->Redirect("sus.pjp");
}
}
Remove semicolon(;) after if else if then it will work. Try it...
Remove Semicolon after if else condition and try it below code
function check()
{
$sqlquery = mysql_query("SELECT * FROM clients WHERE id='$this->ClientID'
AND username='$this->ClientUSERNAME'") or die(mysql_error());
$showmysql = mysql_fetch_array($sqlquery );
$statusOK = $showmysql['status'];
if ($statusOK == "Active" || "1"){
return true;
}
else if ($statusOK == "Pending"){
$this->Redirect("pending.php");
}
else if ($statusOK == "Susspended"){
$this->Redirect("sus.pjp");
}
}
Related
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 1 year ago.
Improve this question
Trying to use a $_GET within a $_GET
It's not throwing any errors but isn't working the way I want it to. It's been a while since I've done this so I don't know if I'm overlooking something or not. I'm trying to be able to do something like index.php?chatroom&id=1
$pgtitle = '';
$cractive = '';
$dactive = '';
$acactive = '';
$pgChat = '';
if(isset($_GET['chatroom'])){
$cractive = 'active';
if (isset($_GET['cid']) == "1") {
$pgChat == 'Global Chatroom';
}else if(isset($_GET['cid']) == "2"){
$pgChat == 'AK Chatroom';
}else if(isset($_GET['cid']) == "3"){
$pgChat == 'AZ Chatroom';
} else {
echo '<meta http-equiv="refresh" content="0; URL=index.php?chatroom&cid=1">';
}
}else{
header('Location: index.php?dashboard');
}
isset() returns a boolean not the content of the variable, and you was using == instead of = in $pgChat == 'Global Chatroom';, here is an example using your code for something like index.php?chatroom&cid=1:
if (isset($_GET['chatroom'])) {
$cractive = 'active';
if (isset($_GET['cid'])) {
if ($_GET['cid'] == "1") {
$pgChat = 'Global Chatroom';
} elseif ($_GET['cid'] == "2") {
$pgChat = 'AK Chatroom';
} elseif ($_GET['cid'] == "3") {
$pgChat = 'AZ Chatroom';
} else {
echo '<meta http-equiv="refresh" content="0; URL=index.php?chatroom&cid=1">';
}
} else {
echo '<meta http-equiv="refresh" content="0; URL=index.php?chatroom&cid=1">';
}
}
EXTRA: You can do the same thing in that way if you wanna.
$chats = [
'1' => 'Global Chatroom',
'2' => 'AK Chatroom',
'3' => 'AZ Chatroom',
];
if (isset($_GET['chatroom'])) {
$cractive = 'active';
if (isset($_GET['cid']) && isset($chats[$_GET['cid']])) {
$pgChat = $chats[$_GET['cid']];
} else {
echo '<meta http-equiv="refresh" content="0; URL=index.php?chatroom&cid=1">';
}
}
Currently losing it.
I have a page that has a condition that checks if a user is an Admin or Reparateur (Repair guys, translated)
When you login, the goal is to make sure that an admin user is only able to login from the $admin_ip thats been entered.
This piece of code is before the statements:
$admin_ip = "xxx.xxx.xxx.180";
$login_ip = $_SERVER['REMOTE_ADDR'];
Later, the conditions checks it:
if ($functie == "Admin" or "Reperateur" AND $login_ip == $admin_ip) {
return true;
} else if ($login_ip != $admin_ip AND $functie == "Admin" or "Reperateur") {
return false;
} else {
return true;
}
Debugging shows the statement should be false:
Debugging screenshot:
Am I just not seeing it or missing something?
Like #PaulT. said:
The or check is invalid. Should be: if (($functie == "Admin" or $functie == "Reperateur") AND ... same in the next else if too.
So, the condition is fixed with the following:
if (($functie == "Admin" or $functie == "Reperateur") AND $login_ip == $admin_ip) {
return true;
} else if (($functie == "Admin" or $functie == "Reperateur") AND $login_ip != $admin_ip) {
return false;
} else {
return true;
}
This question already has answers here:
The 3 different equals
(5 answers)
Closed 5 years ago.
why the IF(the lastest one with else if and else) is doing all the time only first condition and only the first part ($filtry_1value[$key] = 'min_cena'), even if the condition shouldnt be true. I have another solution (less dynamic), if I will not fix this one, but I would like to know, why it is not working... I think it will be a trivial thing, but I cannot see it.
PS: I am working with laravel.
$filtry_1value = ['stat', 'lokalita', 'patro', 'min_cena', 'max_cena', 'min_uzitna_plocha', 'max_uzitna_plocha'];
foreach ($filtry_1value as $key => $filtr_1value) {
$filtr_1value = \Request::has($filtr_1value) ? \Request::get($filtr_1value) : null;
if(!empty($filtr_1value)){
if ($filtry_1value[$key] = 'min_cena' OR $filtry_1value[$key] = 'min_uzitna_plocha') {
$query->where(substr($filtry_1value[$key], 4),'>=',$filtr_1value);
}
elseif ($filtry_1value[$key] = 'max_cena' OR $filtry_1value[$key] = 'max_uzitna_plocha') {
$query->where(substr($filtry_1value[$key], 4),'<=',$filtr_1value);
}
else {
$query->where($filtry_1value[$key],'=', $filtr_1value);
}
}
}
may be-
foreach ($filtry_1value as $key => $filtr_1value) {
$filtr_1value = \Request::has($filtr_1value) ? \Request::get($filtr_1value) : null;
if(!empty($filtr_1value)){
if ($filtry_1value[$key] == 'min_cena' OR $filtry_1value[$key] == 'min_uzitna_plocha') {
$query->where(substr($filtry_1value[$key], 4),'>=',$filtr_1value);
}
elseif ($filtry_1value[$key] == 'max_cena' OR $filtry_1value[$key] == 'max_uzitna_plocha') {
$query->where(substr($filtry_1value[$key], 4),'<=',$filtr_1value);
}
else {
$query->where($filtry_1value[$key],'=', $filtr_1value);
}
}
}
You need to use the double equal sign for comparisons. == not a single =
Your if's should look like:-
if ($filtry_1value[$key] == 'min_cena' OR $filtry_1value[$key] == 'min_uzitna_plocha') {
// ...
} elseif ($filtry_1value[$key] == 'max_cena' OR $filtry_1value[$key] == 'max_uzitna_plocha') {
// ...
}
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Please professional programmers in the house, what is wrong with this code?
I get this error whenever i try to run it.
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\a\go.php on line 8
The php code:
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if (
$term = 'First';
$level='js1';
)
{
header("Location: result.php");
exit();
}
elseif (
$term = 'First';
$level='js2';
)
{
header("Location: result2.php");
exit();
}
else {
$error = "Entry is invalid";
}
?>
Check your if condition. The if and else if conditions must not contain any semicolons. If you are using two comparisons you must use && or || in between them. If you are using = in the if and elseif statement then it will always return true.
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if ($term == 'First' && $level=='js1')
{
header("Location: result.php");
exit();
}
else if ($term == 'First' && $level='js2')
{
header("Location: result2.php");
exit();
}
else {
$error = "Entry is invalid";
}
?>
Change your if condition
it should be
if($term = 'First'&& $level='js1') or if($term = 'First'|| $level='js1')
elseif ($term = 'First' && $level='js2') or elseifif($term = 'First'|| $level='js2')
not
if ($term = 'First'; $level='js1';)
elseif ($term = 'First' ; $level='js2';)
All of your if statements have a malformed format. All you are doing is setting variables within your if statement. Therefore you are not using assignment operators properly. An example of how your if statement should look is:
if($condition === true || $condition2 == 'hello'){
doSomething();
} else if($condition === false || $condtion2 == 'bye'){
doSomethingElse();
}
EDIT: Also i would recommend working on your code indentation skills, this will really help to read your code in the future.
You are not making correct boolean expressions in those ifs.
if ($term === 'first' && $level === 'js1') {...}
elseif($term === 'First' && $level === 'js2') {...}
Also, I strongly recommend you to put a die(); after a redirect to avoid unnecessary load (unless you need to execute code after the redirect).
try this.
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if( $term == 'First' && $level=='js1'){
header("Location: result.php");
exit();
} elseif ( $term == 'First' && $level=='js2'){
header("Location: result2.php");
exit();
} else {
$error = "Entry is invalid";
}
?>
If there is a header already sent error you receive then put ob_start() to top of your php file OR You can also use javascript for this like below.
<script>window.location.href = "a.php";</script>
I'm having an issue with a login script. The rest of it works fine, but there is something odd happening here. The issue is that even though $IPCHK is returning true the elseif function does not execute. It only executes when I set $IPCHK to jibberish. Any help would be great. Thanks in advance
if ($Numrows == 0)
{
if ($Fail >= 3)
{
$Connection = connectToDb();
//return true, false,pending
$IPCHK = checkIP();
$IPCHK = true; //forcing it to be true and still broke
//If no ip id there
if($IPCHK == false)
{
$IP = getIP();
$Query = "INSERT INTO ip VALUES ('','$IP',Now())";
mysqli_query($Connection, $Query)
or die(error(mysqli_error($Connection)));
echo "You have failed to login too many times";
echo "<br />Please <a href='login.php'>try again</a> later.";
$Lock = true;
}
//If ip is there but timer is not up
elseif ($IPCHK == 'pending')
{
echo "You have failed to login too many times";
echo "<br />Please <a href='login.php'>try again</a> later.";
$Lock = true;
}
//Timers Up
elseif ($IPCHK == true) //here does not execute when it returns true
{
$_SESSION['FailedLogin'] = 0;
$Lock = false;
}
else
{
error("End of if check");
}
}
else
{
$Fail = 3 - $Fail;
$_SESSION['FailedLogin'] = $_SESSION['FailedLogin'] + 1;
$Error = $Error."<br />You have ".$Fail." attempts remaining";
}
}
In your Condition you have
elseif ($IPCHK == 'pending')
then
elseif ($IPCHK == true)
the second else will never execute because $IPCHK == 'pending' means also that $IPCHK == true
if you want to execute your second else you have to change the seconde condition to somethig like this
elseif($IPCHK == 'done')
or simply use === like this
elseif($IPCHK === 'pending')
then
elseif($IPCHK === true)
Lamari Alaa is correct, and the relevant documentation entry on type juggling can help understand why.
The following script outputs: boolean = string:
$test = true;
if( $test == 'pending' ) {
echo 'boolean = string';
} else if ( $test ) {
echo 'boolean != string';
}
This is because the string 'pending' is being coerced into a boolean value before being compared to the boolean value true. Since it evaluates as true, the first condition is taken. Consider replacing == 'pending' to === 'pending'