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 3 years ago.
Improve this question
I'm building a functionality which displays a message dynamically, i.e if the forms are correctly filled or not.
I came across this piece of code and I don't understand how does it really work.
if(true) {
$this->flash('Yay ! File uploaded successfully', 'success');
} else {
$this->flash('There is some error', 'error');
From what I've already looked for, I guess it's used to see whether or not there is an array available, since PHP returns false if there isn't one.
(according to PHP manual )
I still don't get how does this work, there is no variables such as if($foo) but just plain boolean on this condition.
And yes, it seems to work as intended.
Thanks for your enlightments.
This looks like a debugging statement left in.
if(true)
This is always true, so you could remove the test entirely and just run with the true statement.
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 2 years ago.
Improve this question
I have a PHP form that when loads will get some variables. Not all variables are set. In the code I can see if the Variable has been defined by using strlen() and that seem to be working but when I apply an if statement it doesn't seem to work?
GetSettingValue() is a function to get the value in a file, the item in the file might not exist
the code I have tried is:
if (strlen(GetSettingValue("Latitude"))==0);{
logEntry("Lat== 0");
}
Just prior to this statement I print the results of strlen(GetSettingValue("Latitude")) and it displays 0 (this is the expected result) And the logEntry gets processed.
But if I want to not enter the if statement I used:
if (strlen(GetSettingValue("Latitude"))!=0);{
logEntry("Lat== 0");
}
and the results of strlen(GetSettingValue("Latitude")) right before the if statement shows 0
But the code will process the logEntry. It seems like the result of strlen() doesn't matter?
Any ideas or a better method?
Just remove the ; semicolon after the parenthesis and it'll work absolutely fine.
Correction:
if (strlen(GetSettingValue("Latitude"))!=0) { logEntry("Lat== 0"); }
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 5 years ago.
Improve this question
I have a mysql field called "time_of_birth" that is definitely set to NULL.
I have a PHP check on that field like this:
if ($row['time_of_birth'] !== "00:00:00") {
//do this stuff
} else {
//do something else
}
For that field that is definitely set to NULL, it's doing the "do this stuff". Isn't NULL different than "00:00:00"? I would expect it to do "do something else" because it's not exactly equal to "00:00:00".
What am I missing here?
I think it is doing it correctly. It is not seeing null as equal to '00:00:00' !== is a proof that it is not seeing it as same and entering that block.
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'm currently having an issue with PHP, I'm trying to compare two POST variables using an if statement. However when i use != it will not work, but == will work and i don't understand why.
if($_POST["PasswordSignUp"] != $_POST[PasswordSignUpRepeat]){
setcookie("PassMatch","Error");
}
Edit:
Okay, i just had an idea that may fix my problem, at the moment i am using the cookie as basically a global variable. Is there a way to define a global variable to use from page to page without having to 'include' or 'require' it into the code.
$_POST[PasswordSignUpRepeat] should be $_POST['PasswordSignUpRepeat']. Also, use paranthesis in comparison. It isn't mandatory, but it's a good process to follow.
if(($_POST["PasswordSignUp"]) != ($_POST['PasswordSignUpRepeat'])){
setcookie("PassMatch","Error");
}
Try below:-
if($_POST['PasswordSignUp'] !== $_POST['PasswordSignUpRepeat']){
setcookie("PassMatch","Error");
}
!== will check fr value and type.
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
i have the if statement below i am trying to make sure that the variable client2 is not empty before doing the update, as the update has to be performed to that client, but ever time i uncomment the if statement it gives a white screen
if(!empty($client2)
{
mysqli_query($con,$query) or die ("Could not update ");
header('Location: preview.php?=client=$client');
}
what i would like is for it not to produce a white screen i suspect it is minor error i have overlooked
the problem also existed before i added
header('Location: preview.php?=client=$client');
this was added as it the final step it needs to do after doing the update but i will have to add a check in to display the error if it fails the update before doing the header but for now i am focusing on getting it to do the update regardless of mysql errors
Your header is wrong you should do it like this:
header("Location: preview.php?client=$client");
You've also forgot a ) here:
if(!empty($client2))
You do miss a closing bracket in your if. Empty is a function and needs to be opened and closed with brackets (). As is the IF function. In other words, you don't close your IF function so PHP assumes that everything after emtpy() is still part of the IF closure.
Also, try never working (in development env ofc) without display_error being abled.
Besides that, your header function has a '=' after the question mark. Its not needed and will eventually fail.
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
New PHP programmer here. Need some syntax help.
Like I know what im trying to do, here, check if that session variable is set and if its a certain string value, but the "(" you need for isset is messing the syntax up. I can't find the help im looking for via google for what is really a very simple syntax question, so I had to come here.
if (isset($_SESSION['IsValid'] AND $_SESSION['IsValid']=="Yes")) {
}else{
}
Typos:
if (isset($_SESSION['IsValid']) AND $_SESSION['IsValid']=="Yes") {
^---missing ^---only one ) here
isset() is a function and checks a SINGLE variable if it "exists". You're trying to isset() the result of your AND operation, which is illegal syntax.
if( isset($_SESSION['IsValid']) && $_SESSION['IsValid'] == "Yes" ) {