unexpected T_IF Issues

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

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

unexpected T_IF Issues

Post by ghadacr »

Hi guys/girls,

I'm tyring to construct an IF ELSE statement, but i keep on getting the following error message
Parse error: syntax error, unexpected T_IF in on line 116

Which is this bit of code,

Code: Select all

echo '<td>'.if($row['Confirmed' ] > 0) { echo "<a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a>" }else{.'<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>';
All help apperciated, thanks

Here is the rest of the code:

Code: Select all

<?PHP
extract($_GET);
$daterep = str_replace("/","-",$datefrom);
$datereps = str_replace("/","-",$dateto);


$newdate = date ("d M Y", strtotime ($daterep)); 
$newdates = date ("d M Y", strtotime ($datereps)); 

setcookie("from", $newdate, time(  )+600);
setcookie("to", $newdates, time(  )+600);
setcookie("hotel", $subcat, time(  )+600);

?>
<?PHP include 'opendb.php'; ?>

<?PHP include 'header.php'; ?>

<?php 


if(isset($_GET))
{

extract($_GET);


$optionsheld = $_GET['optionsheld'];
$confirmedroom = $_GET['confirmedroom'];
$cat = $_GET['cat'];
$Season = $_GET['Season'];


$query = mssql_init ("sp_SearchRooms"); 

mssql_bind($query, "@DateTo", $newdate, SQLVARCHAR);

mssql_bind($query, "@Season", $Season, SQLVARCHAR);

mssql_bind($query, "@resortID", $cat, SQLINT2);

mssql_bind($query, "@DateFrom", $newdates, SQLVARCHAR);

mssql_bind($query, "@HotelID", $subcat, SQLVARCHAR);

mssql_bind($query, "@SearchConfirmed", $groupname, SQLVARCHAR);

mssql_bind($query, "@SearchOptions", $optionsheld, SQLVARCHAR);

//mssql_bind($query1, "RETVAL", &$HotelRoomID2, SQLINT2);

if (($result = mssql_execute($query)) === false) 
{ 
    die('Could not execute the query ' . $sql ); 
} 
//$held = "1";

	
//$que = mssql_init ("sp_SearchByName"); 

//mssql_bind($query, "@ClientName ", $optionsname, SQLVARCHAR);

//mssql_bind($query, "@UserName", $username, SQLVARCHAR);

//mssql_bind($query, "@SearchOptionsHeldByMe", $held, SQLINT2);

//if (($res = mssql_execute($que)) === false) 
//{ 
//    die('Could not execute the query ' . $sql ); 
//} 
	


?> 
<?PHP

$count=mssql_num_rows($result);	
//$count=mssql_num_rows($res);

 if ($count == 0)
  {
echo "<p>Sorry, your search returned no results</p><br><input type='button' value='Retry' onClick='history.go(-1)'>";

} else {

?>

<form action="roomhold.php" method="get"> 
  <table width="108%" border="0">
    <tr> 
      <td width="19%"></td>
      <td width="8%"><strong>Hotel name:</strong></td>
      <td width="8%"><strong>Room Type:</strong></td>
      <td width="8%"><strong>Available From:</strong></td>
      <td width="8%"><strong>Available To:</strong></td>
      <td width="9%"><strong>Requested from</strong></td>
      <td width="9%"><strong>Requested To:</strong></td>
      <td width="5%"><strong>Notes</strong></td>
      <td width="44%">&nbsp;</td>
    </tr>
    <?php 

	
while ($row = mssql_fetch_array($result))
		
{ 
    echo '<tr>';
	echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
    echo '<td>'.if($row['Confirmed' ] > 0) { echo "<a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a>" }else{.'<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>'; 
    echo '</tr>'; 

}

}



?>
    <tr> 
      <td colspan="7"><input type="Submit" value="Hold Room"> <input type='button' value='Back' onClick='history.go(-1)'> 
        <INPUT name="button" type="button" onClick="location.href='http://pb-sql/admin.php'" value="Cancel"> 
      </td>
    </tr>
  </table> 
</form> 

<?PHP include 'footer.php'; ?>
<?PHP }} 
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please indent this code
while ($row = mssql_fetch_array($result))

{
echo '<tr>';
echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>';
echo '<td>' . $row['HotelName' ] . '</td>';
echo '<td>' . $row['RoomType' ] . '</td>';
echo '<td>' . $row['AvailableFrom' ] . '</td>';
echo '<td>' . $row['AvailableTo' ] . '</td>';
echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
echo '<td>' . $row['Notes' ] . '</td>';
echo '<td>'.if($row['Confirmed' ] > 0) { echo "<a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a>" }else{.'<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select ' . $row['RoomType'] .' to update</td>';
echo '</tr>';

}

}
very carefully.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Code: Select all

while ($row = mssql_fetch_array($result))
		
    { 
        echo '<tr>';
	echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
        echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
        echo '<td>'.if($row['Confirmed' ] > 0) { echo "<a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a>" }else{.'<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>'; 
        echo '</tr>'; 

    }

}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

echo '<td>'.if(
You cannot concatenate a string and an if-statement.

btw: a string literal is not bound to one line and echo can take more than more parameter which makes something like

Code: Select all

while ( $row=mssql_fetch_array($result)) {
  echo '
    <tr>
      <td>
        <a href="roomdetails.php?HotelRoomID=' , $row['HotelRoomID'] , '">More information on hotel room</a>
      </td>
      <td>' , $row['HotelName' ] , '</td>
      <td>' , $row['RoomType' ] , '</td>
      <td>' , $row['AvailableFrom' ] , '</td>
      <td>' , $row['AvailableTo' ] , '</td>
      ...
possible.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Ok how would you manuiplate in my script...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I would probably replace the dot by a semi-colon, insert a linebreak before the if and then indent the if-clause carefully.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Would you sy something like this:

Code: Select all

while ($row = mssql_fetch_array($result))
		
{ 
    echo '<tr>';
	echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td>' . $row['HotelName' ] . '</td>'; 
	echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
    echo '<td>'; if($row['Confirmed' ] > 0) { echo "Hello" }else{ echo "<input type=checkbox name=HotelRoomID[] value=$row['HotelRoomID'] />Select $row['RoomType'] to update" } echo '</td>'; 
    echo '</tr>'; 



}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

1 out of 3


(btw: even with 3 out of 3 there are other issues, but then you have a chance to see them)
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Code: Select all

echo '<td>'; if($row['Confirmed' ] > 0) { echo "Hello" }else{ echo "<input type=checkbox name=HotelRoomID[] value=$row['HotelRoomID'] />Select $row['RoomType'] to update" } 
	echo '</td>'; 
    echo '</tr>'; 



}
This is giving me the following errors:
Parse error: syntax error, unexpected '}', expecting ',' or ';'
could you please show me how to resolve this... Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, my previous advices were so obviously stupid that you didn't even try them. Why would you want more of them?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

I did try them and i didnt get anything.... Or maybe i'm not doing it correctly......
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

linebreak?
carefully indented if-statement?
I don't see it.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Here it is:

Code: Select all

echo '<td>'; 
	if  ($row['Confirmed' ] > 0)  { 
			echo "Hello" } else { 
			   echo "<input type=checkbox name=HotelRoomID[] value=$row  ['HotelRoomID'] />Select $row['RoomType'] to update" 
			   
			   } 
echo '</td>'; 
echo '</tr>'; 



}
User avatar
idevlin
Forum Commoner
Posts: 78
Joined: Tue Jun 26, 2007 1:10 pm
Location: Cambridge, UK

Post by idevlin »

Put a ';' after

Code: Select all

{ echo "Hello"
and after

Code: Select all

to update"
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Code: Select all

if  ($row['Confirmed' ] > 0)  { 
			echo "Hello"; 
			} else { 
			   echo '<input type="checkbox" name="HotelRoomID[]" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update';	   
			   }
Post Reply