If statement not working

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
Dataguru
Forum Newbie
Posts: 2
Joined: Tue Mar 13, 2012 5:29 pm

If statement not working

Post by Dataguru »

I'm attempting rather unsuccessfully to conditionally insert a form action based on a value from a field in my query.
If the value of Trap = "Edit" I want to point the page to the edit record page, else send it to an add record page.

note,

Code: Select all

<?php echo $row_RS_ProjReports['Trap'] ?> 
displays either the text "Edit" or "Create" based on whether a record for that month's report already exists or not.

Code: Select all

<?php 
  $FName = NULL;
  if ($row_RS_ProjReports['Trap']="Edit") { 
		 $FName = "ReportMonthlyEdit.php"; } { 
		 $FName = "ReportMonthlyAdd.php"; }?>
$FName always echos: ReportMonthlyAdd.php

Could someone tell me what I'm screwing up?

Thanks,
Betty (php newby)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: If statement not working

Post by Celauran »

This is an assignment, not a comparison, so will always be true.

Code: Select all

if ($row_RS_ProjReports['Trap']="Edit")
What's with the second set of braces? Did you forget an else? That last block will always be executed.

Code: Select all

if ($row_RS_ProjReports['Trap']="Edit")
{
    $FName = "ReportMonthlyEdit.php";
}
{
    $FName = "ReportMonthlyAdd.php";
}
Dataguru
Forum Newbie
Posts: 2
Joined: Tue Mar 13, 2012 5:29 pm

Re: If statement not working

Post by Dataguru »

Cool thanks!
Yes, forgot the else and added the second equal sign and it appears to be working.

Code: Select all

<?php 
    $FName = NULL;
    if ($row_RS_ProjReports['Trap']=="Edit") { 
	 $FName = "ReportMonthlyEdit.php"; 
	 } else { 
	 $FName = "ReportMonthlyAdd.php"; 
	 }
?>
Post Reply