Have a bit of a problem with some current code we're using Android to POST to PHP where using the following code
$fbid = $_POST['fbid'];
if($fbid == "no"){
echo 'no fbid';
}else{
echo 'fbid look for user';
}
We used the following strlen($fbid) which returns 2
All the posted strings don't seem to match and when used strlen() on all equal the correct amount - any ideas? could this be encoding problem?
Just as a trivial suggestion:
if($fbid == "no"){
echo 'no fbid';
}else{
echo 'fbid look for user';
}
Related
I am using Views php in Drupal 6. I need to do an if statement to find if nodehierarchy_parent is equal to the value 0. Then do something. Right now I have it set to if the value contains a 0. My code is below.
<?php
if (strpos($data->nodehierarchy_parent,'0')) {
print 'hello';
}
else print $data->nodehierarchy_parent;
?>
I am new to stack. John's comment solved my problem but I cant mark his comment as correct answer. Below is the final code that worked.
<?php
if ($data->nodehierarchy_parent == 0) {
print 'hello';
}
else print $data->nodehierarchy_parent;
?>
echo (strpos($data->nodehierarchy_parent,'0') === false)
? $data->nodehierarchy_parent
: 'hello';
When people search for a real estate agent by zip code they will see a message on the site I'm working on that reads: There are x number of our Agents in your neighborhood.
x is the number determined by this php code:
<?php echo isset($total_record) ? $total_record : "";?>
if the number is Zero, the message sounds dumb (There are 0 number of...)
How do I change the message just for those cases with 0 as a search result? so that a different message appears? Something like - Sorry, we don't have any Agent in your immediate area.
Any help, much much appreciated.
Use a simple if statement:
if (isset($total_record) && $total_record > 0){
echo $total_record." number of our Agents in your neighborhood";
} else {
echo "Sorry, we don't have any Agent in your immediate area.";
}
if (isset($total_record))
{
if ($total_record > 0)
{
echo "There are {$total_record} of our Agents in your neighborhood.";
}
else
{
echo "There are no Agents in your neighborhood.";
}
}
Use the empty function rather than isset. The empty function checks if a variable exists and has a value. 0, false, and a few other values are also considered empty, check the manual for a full listing.
echo !empty($total_record) ? 'There are ' . $total_record . ' number of our Agents in your neighborhood.' : 'Sorry, we don\'t have any Agent in your immediate area.';
Hi Guys i am having a very peculiar problem i have written a small code so that it is possible to sign up to the website i am creating with a few restrictions to each field however from what i see the code seems ok but each time i try to use the php code with html code the browser is always printing part of the code like this:
"11){ echo 'Username needs at least 6 and maximum 11 characters'; } else if (strpos($Username, '#') != 0) { echo ' Username cant be your email'; } ?>"
<?php
$Username = 'aasd';
if (strlen($Username) < 6 || strlen($Username) > 11){
echo 'Username needs at least 6 and maximum 11 characters';
}
else if (strpos($Username, '#') != 0) {
echo ' Username cant be your email';
}
?>
From what i can see the code is correct but i can't seem to find the reason as to why this is happening am i missing something in the PHP code? do i have some condition or operator that is not set in the right way?
Thank you first hand to all those who reply
I'm new to PHP, and just creating a simple website.
At the moment, I have a header with some links (i.e. blog, faq, home, gaming etc). I'm trying to use GET functions to show new content in a container on the webpage. I've tried having them link to the index and to a specific page, like
Home
and then having some PHP in the html body...
<?php
if ($_GET[page] == "faq") {
$result === 'FAQ';
} else {
$result === 'Non-FAQ';
}
echo $result;
?>
just to see if it would work, and lo and behold, it doesn't.
So, that's basically the gist of what's happening. It's baffled me for the past few hours, and would really appreciate some help
Thanks
You aren't using the assignment operator to assign a value to $result. Use a single equals sign, ie
<?php
if ($_GET['page'] == "faq") {
$result = 'FAQ';
} else {
$result = 'Non-FAQ';
}
echo $result;
?>
<?php
if ($_GET[page] === "faq") {
$result = 'FAQ';
} else {
$result = 'Non-FAQ';
}
echo $result;
?>
If you want to DEFINE a string you use one "=", if you want to compare it you use "===" (or ==) :)
I'm trying to see if the user has entered a website URL into the database with the following code. If the user did not enter their website's URL, do not display anything. If the user did enter their website, display the website.
I think I'm doing it wrong.
<?php
if (!empty($url))
{
echo'';
} else {
echo'p>Website: <?php echo "http://","$url"; ?></p>';
}
?>
Apart from the wrong order (you need to remove ! before the empty()), you also have some errors in the echo part: the < is missing for the < p > tag and you are including php tags in your string.
It should read something like:
echo '<p>Website: http://' . $url . '</p>';
what you've got there is that you're checking if it's NOT empty (that is, there is some data), you're echoing an empty string. If it IS empty, then you're echoing it out.
Remove the ! in the first line and you should be right.
You're simple mismatching the meaning of "!" :
<?php
if (!empty($url))
{
echo'p>Website: <?php echo "http://","$url"; ?></p>';
} else {
echo'';
}
?>