Parse error: syntax error, unexpected T_IF

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
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Parse error: syntax error, unexpected T_IF

Post by ghadacr »

I keep getting the above error , i 'm not sure where the error is coming from, any help would be apperciated

Error recieving
Parse error: syntax error, unexpected T_IF

Code: Select all

<?php 
while ($row = mssql_fetch_array($result)) 
{ 
    echo '<tr>'; 
    echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td><input name="DummyRoom" type="hidden" value="' .$rows['DummyRoom']. '" />'. if( $rows['DummyRoom'] == 1 ){echo "Yes" }else { echo "No" } .' </td>'; 
 

} 
?>
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Post by dhrosti »

semi colon is needed just before the 'if'.

edit: sorry, i didnt realise what you were trying to do. the if statement doesn't have to be in the same line.

eg...

Code: Select all

echo "<td>something";
if (condition) {
  echo "something else";
} else {
  echo "more stuff";
}
echo "</td>";
or you could use .= like...

Code: Select all

$text = "<td>something";
if (condition) {
  $text .= "something else";
} else {
  $text .= "more stuff";
}
$text .= "</td>";

echo $text;
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Nice try but that didnt work all i got was
Parse error: syntax error, unexpected ';' in
code:

Code: Select all

while ($row = mssql_fetch_array($result)) 
{ 
    echo '<tr>'; 
    echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td><input name="DummyRoom" type="hidden" value="' .$rows['DummyRoom']. '" />'. ;if( $rows['DummyRoom'] == 1 ){echo "Yes" }else { echo "No" } .' </td>'; 
	echo '<td>' . $row['DummyName' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td>'.$row['HotelID' ] . '<input name=HotelID type=hidden value="'. $row['HotelID']. '"></td>';
	echo '<td>' . $row['Notes' ] . '</td>'; 
    echo '<td><input type="radio" name="HotelRoomID" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>'; 
    echo '</tr>'; 

}
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

error is coming becouse you've puted dot "." in place where it should be

Code: Select all

.$rows['DummyRoom']. '" />'. if( $rows[
here it is

Code: Select all

while ($row = mssql_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['RoomType' ] . "</td>";
    echo "<td><input name=\"DummyRoom\" type=\"hidden\" value=" . $rows['DummyRoom']. " />";
	if( $rows['DummyRoom'] == 1 )
		{
			echo "Yes";
		}
			else
		{
			echo "No";
		}
	echo "</td>";
    echo "<td>" . $row['DummyName' ] . "</td>";
    echo "<td>" . $row['AvailableFrom' ] . "</td>";
    echo "<td>" . $row['AvailableTo' ] . "</td>";
    echo "<td>".$row['HotelID' ] . "<input name=\"HotelID\" type=\"hidden\" value=" . $row['HotelID'] . "></td>";
    echo "<td>" . $row['Notes' ] . "</td>";
    echo "<td><input type=\"radio\" name=\"HotelRoomID\" value=" . $row['HotelRoomID'] . " />";
	echo "Select  " . $row['RoomType'] . " to update</td>";
    echo "</tr>";

}
try to write code in your way, but keep in mind to write it to be more easier to read.

regards ddragas
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Thanks for the assitance, that helped just great!!!!!
Post Reply