Page 1 of 1
unexpected T_ELSE
Posted: Sun Mar 08, 2009 1:50 pm
by system5
Hi again!
Been getting:
Parse error: syntax error, unexpected T_ELSE in /home/grads/public_html/computing_project/login5/bookingtest.php on line 30 as my error.
I have a feeling its something stupid that I have done, but I just can't seem to spot the cause.
Code: Select all
<?
include("include/activity.php");
?>
<html>
<title>Room Booking</title>
<body>
<?
/**
* User has submitted form without errors and user's
*/
if(isset($_activity['useredit'])){
unset($_activity['useredit']);
echo "<h1>Room Booking Success!</h1>";
echo "<p><b>$activity->username</b>, Booking done. "
."<a href=\"main.php\">Main</a>.</p>";
}
else{
?>
<?
/**
* If user is not logged in, then do not display anything.
*/
if($activity->logged_in){
if(isset($_activity['bookingSuccess'])){
/* Registration was successful */
if($_activity['bookingSuccess']){
echo "<h1>Booked</h1>";
echo "<p>Thanks!".$_activity['bookingName']."</b>, your booking is now part of the system! "
."Click here <a href=\"main.php\">to go back</a>.</p>";
}
/* Registration failed */
else{
echo "<h1>Failed to Book</h1>";
echo "<p>Theres been a error for that roomname<b>".$_activity['bookingName']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_activity['bookingSuccess']);
unset($_activity['bookingName']);
}
?>
<h1>Room Booking in name of: <? echo $activity->username; ?></h1>
<form action="process.php" method="POST">
Room Name : <input name="roomName" type="text"><br>
<input name="send" type="submit" value="Submit">
</form>
<?
}
?>
</body>
</html>
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 1:59 pm
by Benjamin
There was a missing closing brace. Try this.
Code: Select all
<?php include("include/activity.php"); ?>
<html>
<title>Room Booking</title>
<body>
<?php
/**
* User has submitted form without errors and user's
*/
if (isset($_activity['useredit'])) {
unset($_activity['useredit']);
echo "<h1>Room Booking Success!</h1>";
echo "<p><b>$activity->username</b>, Booking done. "
. "<a href=\"main.php\">Main</a>.</p>";
} else {
/**
* If user is not logged in, then do not display anything.
*/
if ($activity->logged_in) {
if (isset($_activity['bookingSuccess'])) {
/* Registration was successful */
if ($_activity['bookingSuccess']) {
echo "<h1>Booked</h1>";
echo "<p>Thanks!".$_activity['bookingName']."</b>, your booking is now part of the system! "
."Click here <a href=\"main.php\">to go back</a>.</p>";
} else {
echo "<h1>Failed to Book</h1>";
echo "<p>Theres been a error for that roomname<b>".$_activity['bookingName']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_activity['bookingSuccess']);
unset($_activity['bookingName']);
}
?>
<h1>Room Booking in name of: <?php echo $activity->username; ?></h1>
<form action="process.php" method="POST">
Room Name : <input name="roomName" type="text"><br>
<input name="send" type="submit" value="Submit">
</form>
<?php
}
}
?>
</body>
</html>
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 3:10 pm
by system5
Well that solved that issue.
I also deleted
Code: Select all
# <?
# /**
# * User has submitted form without errors and user's
# */
# if(isset($_activity['useredit'])){
# unset($_activity['useredit']);
#
# echo "<h1>Room Booking Success!</h1>";
# echo "<p><b>$activity->username</b>, Booking done. "
# ."<a href=\"main.php\">Main</a>.</p>";
# }
# else{
# ?>
As I don't think I actually need that.
While were on this subject any idea why i am also getting a:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/grads/public_html/computing_project/login5/bookingtest.php:2) in /home/grads/public_html/computing_project/login5/include/activity.php on line 45
?
Heres the function related to line 45 activity.php
Code: Select all
function activityStart(){
global $database; //The database connection
session_start(); //Tell PHP to start the session
/* Determine if user is logged in */
$this->logged_in = $this->check();
/**
* Set guest value to users not logged in, and update
* active guests table accordingly.
*/
if(!$this->logged_in){
$this->username = $_SESSION['username'] = gs_name;
$this->userlevel = gs_level;
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
}
/* Update users last active timestamp */
else{
$database->addActiveUser($this->username, $this->time);
}
/* Remove inactive visitors from database */
$database->removeInactiveUsers();
$database->removeInactiveGuests();
/* Set referrer page */
if(isset($_SESSION['url'])){
$this->referrer = $_SESSION['url'];
}else{
$this->referrer = "/";
}
/* Set current url */
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
}
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 3:36 pm
by Benjamin
You cannot start a session after you have sent output.
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 4:18 pm
by system5
astions wrote:You cannot start a session after you have sent output.
Right ok, so forgive my stupidity, but whats the difference with me doing a page like this? Except in this case my signup page only works if the user is not logged in.
Code: Select all
<?
include("include/activity.php");
?>
<html>
<title>Sign up page</title>
<body>
<?
if($session->logged_in){
echo "<h1>Registered</h1>";
echo "<p>The user <b>$session->username</b>, already exists and already logged in. "
."<a href=\"main.php\">Main</a>.</p>";
}
else if(isset($_SESSION['regsuccess'])){
if($_SESSION['regsuccess']){
echo "<h1>Registered!</h1>";
echo "<p>Thanks!".$_SESSION['reguname']."</b>, your now part of the system! "
."Click here <a href=\"main.php\">to go back</a>.</p>";
}
else{
echo "<h1>Failed to Register</h1>";
echo "<p>Error for that name:<b>".$_SESSION['reguname']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_SESSION['regsuccess']);
unset($_SESSION['reguname']);
}
else{
?>
<h1>Register</h1>
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>name:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>psw:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td>mail:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" value="Join!"></td></tr>
<tr><td colspan="2" align="left"><a href="main.php">Back to Main</a></td></tr>
</table>
</form>
<?
}
?>
</body>
</html>
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 4:22 pm
by Benjamin
There is a new line character on line one. That counts as output. Assuming you are calling session_start() in activity.php, and there is no output being sent in activity.php, that new line character would be your problem.
Re: unexpected T_ELSE
Posted: Sun Mar 08, 2009 5:09 pm
by system5
astions wrote:There is a new line character on line one. That counts as output. Assuming you are calling session_start() in activity.php, and there is no output being sent in activity.php, that new line character would be your problem.
Ah right
Cheers for the help