If Statement Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

If Statement Problem

Post by micky007 »

Hi Guys,

Any help with my problem would be great, here is my code:

Code: Select all

<? 
if($affstatus == "Pending"){ 
    $protext="Your application to run this campaign is under review, please allow 48hrs to review your application."; 
} elseif($affstatus == "Declined"){ 
    $protext="Your application to run this campaign has been Declined. Please speak with your affiliate manager."; 
} elseif($affstatus == "Approved"){ 
    //display banners etc.. 
    $display=eval('echo "'.$string.'";'); 
    $protext="<table width='741' border='0' cellpadding='2' cellspacing='2'> 
  <tr> 
    <td bgcolor='#FFFFFF'><strong>Banner ID:</strong> <? echo $bannerid; ?><br /> 
      <img src='<? echo $bannerurl; ?>' /></td> 
  </tr> 
  <tr> 
    <td bgcolor='#FFFFFF'><textarea name='BannerCode' id='BannerCode' cols='60' rows='5'><? echo $display; ?></textarea></td> 
  </tr> 
</table>"; 
} 
echo $protext; 
?>
The output is fine if $affstatus is Pending. If value is Approved then nothing is displayed and if the value is Declined then it outputs the text but it outputs it 3 times for some reason.

Again any help on this would be fantastic.

Thank you very much guys
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: If Statement Problem

Post by Jonah Bron »

Code: Select all

$display=eval('echo "'.$string.'";'); 
What's that supposed to do? Lets try this:

Code: Select all

<?php
if($affstatus == "Pending"){
    $protext="Your application to run this campaign is under review, please allow 48hrs to review your application.";
} elseif($affstatus == "Declined"){
    $protext="Your application to run this campaign has been Declined. Please speak with your affiliate manager.";
} elseif($affstatus == "Approved"){
    //display banners etc..
    $protext="<table width='741' border='0' cellpadding='2' cellspacing='2'>
  <tr>
    <td bgcolor='#FFFFFF'><strong>Banner ID:</strong> $bannerid<br />
      <img src='<?$bannerurl' /></td>
  </tr>
  <tr>
    <td bgcolor='#FFFFFF'><textarea name='BannerCode' id='BannerCode' cols='60' rows='5'>$string</textarea></td>
  </tr>
</table>";
}
echo $protext;
?>
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: If Statement Problem

Post by angelicodin »

What about making your if statements === for an absolute equals?
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

Re: If Statement Problem

Post by micky007 »

Hi,

That code needs to be in there as the value of one of the rows in the database has PHP variable tags in it which need to be replaced. It works with this code below.

Code: Select all

<?
//GET BANNERS FOR PROGRAM
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

$query="SELECT * FROM programbanners WHERE ProgramID ='$programid'";
$result=mysql_query($query);
$num=mysql_numrows($result) or die(mysql_error());

$i=0;
while ($i < $num) {
$bannerid=mysql_result($result,$i,"BannerID");
$type=mysql_result($result,$i,"Type");
$code=mysql_result($result,$i,"Code");
$bannerurl=mysql_result($result,$i,"BannerURL");

$string = $code;
$string = addslashes($string); 
?>
Also the code you told me try doesnt look any different except the line you asked about being removed.

Thanks
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

Re: If Statement Problem

Post by micky007 »

angelicodin wrote:What about making your if statements === for an absolute equals?
I've tried, still the same problem :(

Thanks
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: If Statement Problem

Post by Jonah Bron »

Echo the value of $affstatus before the if statement, and confirm that the value you're expecting is what you're receiving.
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: If Statement Problem

Post by angelicodin »

Hmmm, I'll looked at it in my own php editor and it looks correct for the most part (outside of stylizing for coding ;p), so I have no idea why it would be displaying three times if it's anything other than pending. Can you try changing it, so it's IF(){} and for the elseif make them if(){} and see where the code is going weird. Also I would check to see what the actual value is for the $affstatus variable to make sure it's not being changed at some point (who knows). But the only think I can think of why it would be displaying it 3times is, a loop or the value for the conditional is not proper for some reason.

(EDIT: LOL was thinking the same thing)
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

Re: If Statement Problem

Post by micky007 »

Hi Guys,

Thanks for getting back to me, yea i always echo the value of a variable im having a problem with and everything is fine which is why i dont understand why its not working right. Do you mind if i provide you with the php file you can take a look at it for me please?

Also pm me an email address in order to send you the file if your willing to take a look for me.

Thanks for your comments so far guys :)

Thank you.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: If Statement Problem

Post by Jonah Bron »

Can you just post all the code here?
Post Reply