I just need help with a few things. Firstly how would I get the data of a selection when posted.Like
$selection=$_GET['area'];
if ($selection="time"){
echo "Not working yet please come back at a later update.";
}
and also on that note, why is it displaying it even when there is no data sent over the form. I thank any and all help.
It must be == operator you have used = operator which is the assiging operator.You have to use == or === operator for comparisons.For more check comparison operators in php
$selection = trim($_GET['area']);
if ($selection == "time"){
echo "Not working yet please come back at a later update.";
}
The operator "=" is not proper.
You should use "===" to check equality.
<?php
$selection=$_GET['area'];
if ($selection === 'time'){
echo 'Not working yet please come back at a later update.';
}
?>
Always use == or === operators to check conditions
$selection=$_GET['area'];
if ($selection=="time"){
echo "Not working yet please come back at a later update.";
}
you forgot one = your code should be
$selection = $_GET['area'];
if ( $selection == 'time' ) {
echo 'Now working yet please comde back at a later update';
}
using =you are assigning 'time' to $selection which always returnes true
use == instead.
it should be like this.
if ($selection=="time"){
$selection="time"
this assigns $selection variable a value "time".
You should use
if ($selection=="time")
instead of
if ($selection="time")
Related
I have a table with columns
id,name,phone,describe
While fetching the values from this table i am using
$row=mysql_fetch_array($query)
Now i want to check whether
$row['describe']
is returning empty value. How to check in php??
You can use ==0, this will check if it equals to 0:
if ($row['describe']==0) { /* code to do */ }
Or empty(), this will check if it is empty:
if (empty($row['describe'])) { /* code to do */ }
Personally, I would prefer !empty() as this will check if the variable is empty.
Hope this helps, thanks!
Try this :
if(empty($row['describe'])) {
//$row['describe'] is empty
} else {
//$row['describe'] is not empty
}
Also please dont use mysql_*. It's deprecated and removed from PHP 7. Use mysqli_* or PDO.
Use if condition like below
if ($row['describe'] == ""){
echo "Description is empty";
}else{
echo $row['describe'];
}
This can help you. First check the query doesn't return empty then check the describe column is not empty. Only then go for performing action(s).
if ((mysql_num_rows($result) !=0 ) && (!empty($row['describe']) )
{ //PERFORM ACTION }
I want to check if array is empty or not, i wrote few lines of code for it
if(array() == $myArray){
echo "Array";
}
or
if(array() === $myArray){
echo "Array";
}
I'm confused which one to use, as the second condition also checks type. But i think in the case of array we don't need to check their type.
Please anybody can suggest me which one to use.
you can check it by using empty() function like below
<?php
if(empty($myArray)) {
//condition
}
?>
if (! count($myArray)) {
// array is empty
}
Let php do its thing and check for booleans.
Use empty:
if (empty($myArray)) {
...
}
Try this :
<?php
$array = array();
if(empty($array))
{
echo "empty";
} else
{
echo "some thing!";
}
?>
It's always better to check first whether it is array or not and then it is empty or not. I always use like this because whenever I check only empty condition somewhere I don't get the expected result
if( is_array($myArray) and !empty($myArray) ){
.....
.....
}
<?php
if(empty($yourarry)){
}
OR
if(isset($yourarry)){
}
OR
if(count($yourarry)==0){
}
It depends:
Use count==0 if your array could also be an object implementing Countable
Use empty otherwise
array() == $myArray is unreadable, you should avoid it. You can see the difference between count and empty here.
Can anyone explain why this:
if($xml->$ul !== ""){
echo $xml->$ul;
}
if($xml->$ul == ""){
echo "0";
}
does work, while
if($xml->$ul !== ""){
echo $xml->$ul;
}else{
echo "0";
}
does not work?
Am i missing something?
Short explanation: if the xml contains $ul it will echo its value, if it is not contained it will echo 0. Works perfectly with first code, but second code just echos the values, the else is completely ignored.
I appreciate all answers!
You are not doing the same equality check. In the first example you are first checking using !==, then in the second if you are using ==.
See this answer for an explanation of the difference between === equality and == equality. In short, === not only checks the values are equal, but also that the types of the variables being compared are the same as well.
Short question what am I doing wrong?
<?php
if ($arrItem['text']['kachelband_de_external_link'] = "1"){
echo 'target="_blank"';
} else{
}
?>
I always get the output: target="_blank", even if "$arrItem['text']['kachelband_de_external_link']" = 0
Because you are doing an assignment operation instead of comparison on your if statement.
Should be
if ($arrItem['text']['kachelband_de_external_link'] == "1")
See the two equal signs ?
if ($arrItem['text']['kachelband_de_external_link'] == "1"){
echo 'target="_blank"';
}
use == to check conditions
You have to use
if ($arrItem['text']['kachelband_de_external_link'] == "1")
and not only one of "=". If you only use one, you set the var before. By using 2 "=" you compare ;)
if ($_SESSION['user_email']!=$_SESSION['ship_user_email'])
{
$to= $_SESSION['ship_user_email'];
mail($to,$subject,$mail_html,$headers);
}
there is problem in comparing values of both session. value is different but code not working.
print the values of both the session variables and check if there are leading or trailing spaces in the them.
Also check the condition with the '!==' as said by Kerry.
like this
if ( $_SESSION['user_email'] !== $_SESSION['ship_user_email'] )
{
$to= $_SESSION['ship_user_email'];
mail($to,$subject,$mail_html,$headers);
}
also check every step of your code by writing an echo statement and printing out the values of variables. This will help you debug and understand the code properly.
Try using the "!==" operator instead.
you can use <> this operator.