Code executes even when if condition isn't true..
Moderator: General Moderators
Code executes even when if condition isn't true..
I believe the problem is in the code which I have commented out. For some reason it seems to run even when the if condition isn't true, causing the page to always load the default page.
<?php
$Alexa_Last_Image = 106;
$Alexia_Last_Image = 119;
$Allisin_Last_Image = 112;
$Annie_Last_Image = 154;
$Erica_Last_Image = 109;
$Kaylee_Last_Image = 107;
$Mel_Last_Image = 66;
$Monica_Last_Image = 103;
$Sydney_Last_Image = 106;
$total_all_images = $Alexa_Last_Image + $Alexia_Last_Image + $Allisin_Last_Image + $Annie_Last_Image + $Erica_Last_Image + $Kaylee_Last_Image + $Mel_Last_Image + $Monica_Last_Image + $Sydney_Last_Image;
if (!empty($model))
{
if ($model == "Alexa") $max = $Alexa_Last_Image;
elseif ($model == "Alexia and Tyler") $max = $Alexia_Last_Image;
elseif ($model == "Allisin") $max = $Allisin_Last_Image;
elseif ($model == "Annie and Hanna") $max = $Annie_Last_Image;
elseif ($model == "Erica") $max = $Erica_Last_Image;
elseif ($model == "Kaylee") $max = $Kaylee_Last_Image;
elseif ($model == "Monica") $max = $Monica_Last_Image;
elseif ($model == "Sydney") $max = $Sydney_Last_Image;
}
//if (isset($pic) && $pic > $max);
//{
//unset($model);
//unset($pic);
//}
if (empty($model))
{
$model = "Select A Model";
include 'header.php';
include 'firstvisit.php';
include 'footer.php';
}
else
{
if ($model == "Alexa") $path = "alexablkdrscch";
elseif ($model == "Alexia and Tyler") $path = "alextwgrsbg";
elseif ($model == "Allisin") $path = "aliovergr";
elseif ($model == "Annie and Hanna") $path = "anihangg";
elseif ($model == "Erica") $path = "erccampjungle";
elseif ($model == "Kaylee") $path = "kaybluelng";
elseif ($model == "Monica") $path = "moniroselng";
elseif ($model == "Sydney") $path = "sydfence";
include 'header.php';
include 'photos.php';
include 'footer.php';
}
?>
<?php
$Alexa_Last_Image = 106;
$Alexia_Last_Image = 119;
$Allisin_Last_Image = 112;
$Annie_Last_Image = 154;
$Erica_Last_Image = 109;
$Kaylee_Last_Image = 107;
$Mel_Last_Image = 66;
$Monica_Last_Image = 103;
$Sydney_Last_Image = 106;
$total_all_images = $Alexa_Last_Image + $Alexia_Last_Image + $Allisin_Last_Image + $Annie_Last_Image + $Erica_Last_Image + $Kaylee_Last_Image + $Mel_Last_Image + $Monica_Last_Image + $Sydney_Last_Image;
if (!empty($model))
{
if ($model == "Alexa") $max = $Alexa_Last_Image;
elseif ($model == "Alexia and Tyler") $max = $Alexia_Last_Image;
elseif ($model == "Allisin") $max = $Allisin_Last_Image;
elseif ($model == "Annie and Hanna") $max = $Annie_Last_Image;
elseif ($model == "Erica") $max = $Erica_Last_Image;
elseif ($model == "Kaylee") $max = $Kaylee_Last_Image;
elseif ($model == "Monica") $max = $Monica_Last_Image;
elseif ($model == "Sydney") $max = $Sydney_Last_Image;
}
//if (isset($pic) && $pic > $max);
//{
//unset($model);
//unset($pic);
//}
if (empty($model))
{
$model = "Select A Model";
include 'header.php';
include 'firstvisit.php';
include 'footer.php';
}
else
{
if ($model == "Alexa") $path = "alexablkdrscch";
elseif ($model == "Alexia and Tyler") $path = "alextwgrsbg";
elseif ($model == "Allisin") $path = "aliovergr";
elseif ($model == "Annie and Hanna") $path = "anihangg";
elseif ($model == "Erica") $path = "erccampjungle";
elseif ($model == "Kaylee") $path = "kaybluelng";
elseif ($model == "Monica") $path = "moniroselng";
elseif ($model == "Sydney") $path = "sydfence";
include 'header.php';
include 'photos.php';
include 'footer.php';
}
?>
- ILoveJackDaniels
- Forum Commoner
- Posts: 43
- Joined: Mon May 20, 2002 8:18 am
- Location: Brighton, UK
I hate the empty() function. Try this instead - might work a little better:
Code: Select all
<?php
$Alexa_Last_Image = 106;
$Alexia_Last_Image = 119;
$Allisin_Last_Image = 112;
$Annie_Last_Image = 154;
$Erica_Last_Image = 109;
$Kaylee_Last_Image = 107;
$Mel_Last_Image = 66;
$Monica_Last_Image = 103;
$Sydney_Last_Image = 106;
$total_all_images = $Alexa_Last_Image + $Alexia_Last_Image + $Allisin_Last_Image + $Annie_Last_Image + $Erica_Last_Image + $Kaylee_Last_Image + $Mel_Last_Image + $Monica_Last_Image + $Sydney_Last_Image;
if ($model!="")
{
if ($model == "Alexa") $max = $Alexa_Last_Image;
elseif ($model == "Alexia and Tyler") $max = $Alexia_Last_Image;
elseif ($model == "Allisin") $max = $Allisin_Last_Image;
elseif ($model == "Annie and Hanna") $max = $Annie_Last_Image;
elseif ($model == "Erica") $max = $Erica_Last_Image;
elseif ($model == "Kaylee") $max = $Kaylee_Last_Image;
elseif ($model == "Monica") $max = $Monica_Last_Image;
elseif ($model == "Sydney") $max = $Sydney_Last_Image;
}
//if (isset($pic) && $pic > $max);
//{
//unset($model);
//unset($pic);
//}
if ($model=="")
{
$model = "Select A Model";
include 'header.php';
include 'firstvisit.php';
include 'footer.php';
}
else
{
if ($model == "Alexa") $path = "alexablkdrscch";
elseif ($model == "Alexia and Tyler") $path = "alextwgrsbg";
elseif ($model == "Allisin") $path = "aliovergr";
elseif ($model == "Annie and Hanna") $path = "anihangg";
elseif ($model == "Erica") $path = "erccampjungle";
elseif ($model == "Kaylee") $path = "kaybluelng";
elseif ($model == "Monica") $path = "moniroselng";
elseif ($model == "Sydney") $path = "sydfence";
include 'header.php';
include 'photos.php';
include 'footer.php';
}
?>Do a var_dump() on the variable you are having a problem with, and see what it outputs.
Code: Select all
<?php
$Alexa_Last_Image = 106;
$Alexia_Last_Image = 119;
$Allisin_Last_Image = 112;
$Annie_Last_Image = 154;
$Erica_Last_Image = 109;
$Kaylee_Last_Image = 107;
$Mel_Last_Image = 66;
$Monica_Last_Image = 103;
$Sydney_Last_Image = 106;
$total_all_images = $Alexa_Last_Image + $Alexia_Last_Image + $Allisin_Last_Image + $Annie_Last_Image + $Erica_Last_Image + $Kaylee_Last_Image + $Mel_Last_Image + $Monica_Last_Image + $Sydney_Last_Image;
var_dump($model);
if (!empty($model))
{
if ($model == "Alexa") $max = $Alexa_Last_Image;
elseif ($model == "Alexia and Tyler") $max = $Alexia_Last_Image;
elseif ($model == "Allisin") $max = $Allisin_Last_Image;
elseif ($model == "Annie and Hanna") $max = $Annie_Last_Image;
elseif ($model == "Erica") $max = $Erica_Last_Image;
elseif ($model == "Kaylee") $max = $Kaylee_Last_Image;
elseif ($model == "Monica") $max = $Monica_Last_Image;
elseif ($model == "Sydney") $max = $Sydney_Last_Image;
}
//if (isset($pic) && $pic > $max);
//{
//unset($model);
//unset($pic);
//}
var_dump($model);
if (empty($model))
{
$model = "Select A Model";
include 'header.php';
include 'firstvisit.php';
include 'footer.php';
}
else
{
if ($model == "Alexa") $path = "alexablkdrscch";
elseif ($model == "Alexia and Tyler") $path = "alextwgrsbg";
elseif ($model == "Allisin") $path = "aliovergr";
elseif ($model == "Annie and Hanna") $path = "anihangg";
elseif ($model == "Erica") $path = "erccampjungle";
elseif ($model == "Kaylee") $path = "kaybluelng";
elseif ($model == "Monica") $path = "moniroselng";
elseif ($model == "Sydney") $path = "sydfence";
include 'header.php';
include 'photos.php';
include 'footer.php';
}
?>Re: Code executes even when if condition isn't true..
I replaced the code below with this...
if ($pic >= ($max + 1)) $pic = "001";
and that fixed the problem, although I still can't figure out why the code below wouldn't work.
if ($pic >= ($max + 1)) $pic = "001";
and that fixed the problem, although I still can't figure out why the code below wouldn't work.
agtlewis wrote:
if (isset($pic) && $pic > $max);
{
unset($model);
unset($pic);
}
Thanks for the advice but I don't think that will work because php will return an error if you compare a variable that isn't set yet.. I think.ILoveJackDaniels wrote:Code: Select all
if ($model!="")
It will do that on empty() as wellagtlewis wrote:Thanks for the advice but I don't think that will work because php will return an error if you compare a variable that isn't set yet.. I think.ILoveJackDaniels wrote:Code: Select all
if ($model!="")
-
leenoble_uk
- Forum Contributor
- Posts: 108
- Joined: Fri May 03, 2002 10:33 am
- Location: Cheshire
- Contact:
if (isset($pic) && $pic > $max);
{
unset($model);
unset($pic);
}
I think it's just that ; at the end of the 'if' line. Take that out and it should work.
also to avoid confusion I always parenthesise (sic) each separate part of the condition.
if ((isset($pic)) && ($pic > $max))
{
unset($model);
unset($pic);
}
k
{
unset($model);
unset($pic);
}
I think it's just that ; at the end of the 'if' line. Take that out and it should work.
also to avoid confusion I always parenthesise (sic) each separate part of the condition.
if ((isset($pic)) && ($pic > $max))
{
unset($model);
unset($pic);
}
k
- sam
- Forum Contributor
- Posts: 217
- Joined: Thu Apr 18, 2002 11:11 pm
- Location: Northern California
- Contact:
I'll assume that because you haven't set $pic from within your script that you are using it as a passed variable. If so and you are using php 4.1.x or grater than you have to add this to the top of your code. $pic = $_GET["pic"];
[edit]Damn I think leenobal found your error[/edit]
As for the comment of not liking empty(). That is hogwash, it does the same function as ($var == "" || $var == 0) in a lot fewer lines. But whatever you like man.
Cheers Sam
[edit]Damn I think leenobal found your error[/edit]
As for the comment of not liking empty(). That is hogwash, it does the same function as ($var == "" || $var == 0) in a lot fewer lines. But whatever you like man.
Cheers Sam
Right On, that was the problem, I figured it myself after many long hours of scratching my head, but it seems that no one else I showed the code to caught it either till you. Good Call!
leenoble_uk wrote:if (isset($pic) && $pic > $max);
{
unset($model);
unset($pic);
}
I think it's just that ; at the end of the 'if' line. Take that out and it should work.
also to avoid confusion I always parenthesise (sic) each separate part of the condition.
if ((isset($pic)) && ($pic > $max))
{
unset($model);
unset($pic);
}
k