Jump to content

unexpected $end


trilbyfish

Recommended Posts

I get a

Parse error: syntax error, unexpected $end error 

when i try and run a page. I have read that this is to do with not having the right amount of curly brackets. I counted them up, and forund that i have 15 x { and 12 x }, so im prety sure i need to put in an extra 3 x } somewhere in the script, presumably near the end

 

I think this is the code where the curly brackets arent closed:

// Check for $_GET id
if (isset($_GET['id'])) {
    $id = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT * FROM bookingtable WHERE id = $id";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {

 

Where would these 3 end curly brackets be put? i've tried several places, but i still get the same error.

 

I hope this makes sense, and if it hasnt, i will post the full lump of code if anyone is kind enough to say how i can correct it.

 

Thnaks in advance

Link to comment
Share on other sites

We need to see all of your code to be able to tell you where you're missing the brackets.

 

Ken

 

ok

 

<?php

session_name('visit');
session_start();

//check for session value
if(!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']))){

// Redirect the user to the loggedin.php page.
// Start defining the URL.
   $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
   // Check for a trailing slash.
   if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
    $url = substr ($url, 0, -1); // Chop off the slash.
   }
// Add the page.
   $url .= '/members.php';
   
   header("Location: $url");
   exit(); 
// Quit the script.
  }
// This script retrieves all the records from the users table.
// This new version allows the results to be sorted in different ways.


$page_title = 'View the booking table';

require_once ('../project/connect.php'); // Connect to the db.

// Make sure the id that was on the bookingtable page was set, and select the relevent bay record from the sql 'bookingtable' table

// Check for $_GET id
if (isset($_GET['id'])) {
    $id = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT * FROM bookingtable WHERE id = $id";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {




// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5" border ="1">
<tr>
<td align="left"><b>Bay Number</b></td>
<td align="left"><b>08:00 - 09:00 </b></td>
<td align="left"><b>09:00 - 10:00 </b></td>
<td align="left"><b>10:00 - 11:00 </b></td>
<td align="left"><b>11:00 - 12:00 </b></td>
<td align="left"><b>12:00 - 13:00 </b></td>
<td align="left"><b>13:00 - 14:00 </b></td>
<td align="left"><b>14:00 - 15:00 </b></td>
<td align="left"><b>15:00 - 16:00 </b></td>
<td align="left"><b>16:00 - 17:00 </b></td>
</tr>
';


// Fetch and print the record whice corresponds to the bay id from the 'edit' link that was clicked on the bookingtable page


if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo ' <tr>

                <input type="hidden" name="submitted" value="TRUE" />
                <form action="editbay.php?id=' . $row['id'] . '" method="post">
	<td align="left">' . $row['baynumber']     . '</td>
	<td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" value="' . $row['08:00 - 09:00'] . '" /></td>
	<td align="left"><input type="text" name="09:00 - 10:00" size="12" maxlength="30" value="' . $row['09:00 - 10:00'] . '" /></td>
	<td align="left"><input type="text" name="10:00 - 11:00" size="12" maxlength="30" value="' . $row['10:00 - 11:00'] . '" /></td>
	<td align="left"><input type="text" name="11:00 - 12:00" size="12" maxlength="30" value="' . $row['11:00 - 12:00'] . '" /></td>
	<td align="left"><input type="text" name="12:00 - 13:00" size="12" maxlength="30" value="' . $row['12:00 - 13:00'] . '" /></td>
	<td align="left"><input type="text" name="13:00 - 14:00" size="12" maxlength="30" value="' . $row['13:00 - 14:00'] . '" /></td>
	<td align="left"><input type="text" name="14:00 - 15:00" size="12" maxlength="30" value="' . $row['14:00 - 15:00'] . '" /></td>
	<td align="left"><input type="text" name="15:00 - 16:00" size="12" maxlength="30" value="' . $row['15:00 - 16:00'] . '" /></td>
	<td align="left"><input type="text" name="16:00 - 17:00" size="12" maxlength="30" value="' . $row['16:00 - 17:00'] . '" /></td>

</tr>
<tr >
<td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit" </td></tr>

</table>




';

}


echo '</table>';

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {


$errors = array(); // Initialize error array.


// Check for a 08:00 - 09:00 time slot.
if (empty($_POST['08:00 - 09:00'])) {
	$errors[] = 'You forgot to enter something in 08:00 - 09:00.';
} else {
	$eight = escape_data($_POST['08:00 - 09:00']);
}


if (empty($errors)) { // If everything's OK.

{


		// Make the query.
		$query = "UPDATE bookingtable SET 08:00 - 09:00='$eight' WHERE id=$id";
		$result = @mysql_query ($query); // Run the query.
		if (mysql_affected_rows() == 1) { // If it ran OK.

			// Print a message.
			echo '<h1 id="mainhead">Edit a Bay</h1>
			<p>A time slot has been edited.</p><p><br /><br /></p>';	

		} else { // If it did not run OK.
			echo '<h1 id="mainhead">System Error</h1>
			<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message.
			echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. 
			exit();
		}




echo "<p>If you wish to go back and view the bookingtable click <a href = bookingtable.php>here</a></p>";









mysql_free_result ($result); // Free up the resources.	

             }
     }
}


}else{
echo '<p>'. mysql_error() . '<br/>
<br/>Query: ' . $query . '</p>';
}






mysql_close(); // Close the database connection.


?>

 

Thanks

Link to comment
Share on other sites

if ($result = mysql_query($sql)) {

      if (mysql_num_rows($result)) {              //have no end braces, as far as i can tell

 

suggest you download a free php editor that looks at braces

 

also

if ($result) {                                          //have no end brace either as far as i can tell

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 

Link to comment
Share on other sites

in the line

$query = "UPDATE bookingtable SET 08:00 - 09:00='$eight' WHERE id=$id";

i think you should have id = '$id' ";

there are probably other errors as well...

It's probably a good practice to echo your query and even exit there and then... Then, and try them out if you are not sure

by cutting and pasting in the sql window of the database, to see if you are getting the results you expect.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.