Jump to content

[SOLVED] Unexpected $end on last line


soycharliente

Recommended Posts

This is some old code I'm trying to update. It's not REALLY long, but it's a bit to look through. I cannot for the life of me figure out where I screwed up and forgot to put a semi-colon, close a quote, close a brace, etc. I assume that's what the error message means. If not, can someone explain what's really wrong?

 

Parse error: syntax error, unexpected $end in edit.php on line 273

 

I tried commenting out the two require() at the top because I thought maybe I had accidentally hit a key with one of those files open or something and I get the same error message.

 

I don't have an IDE that does PHP color coding. I'm even sitting here looking at the color coding of the code render in the topic and can't see any funky things going on with any strings or functions.

 

Help!

 

<?php
session_start();
require("lib/check.php");
require("lib/main.php");

$the_id = $_GET['id'];
dbconnect();
$sql = "SELECT * FROM lunch_data d
	JOIN lunch_loc el ON d.pid = el.id
	WHERE d.pid = {$the_id}";
$result = mysql_query($sql) OR DIE ("<strong>ERROR</strong><br />{$sql}<br />".mysql_error());
if (mysql_num_rows($result) > 0)
{
$r = mysql_fetch_assoc($result);
$loc = $r['loc'];
$pid = $r['pid'];
$thedate = $r['thedate'];
	$when = explode("-", $thedate);
$rating = $r['rating'];
$spent = $r['spent'];
	$price = explode(".", $spent);
$comments = $r['comment'];
}
else
{
DIE ("No location with that id. Don't try to cheat me.");
}
dbclose();

if ($_POST["Submit"] == "Submit") {
foreach ($_POST as $key => $val) {
	$_POST[$key] = myEscape($val);

$the_id = $_POST['the_id'];
$pid = $_POST['pid'];

$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$error = (empty($month)||empty($day)||empty($year)) ? TRUE : FALSE;

$therating = $_POST['rating'];

$dollars = $_POST['dollars'];
$cents = $_POST['cents'];

$comment = trim($_POST['comment']);

if (!$error) {
	$thedate = "'{$year}-{$month}-{$day}'";
	$rating = (empty($therating)) ? "NULL" : "'{$therating}'";
	$spent = (empty($dollars)||empty($cents)) ? "NULL" : "'{$dollars}.{$cents}'";
	$notes = (empty($comment)) ? "NULL" : "'{$comment}'";

	dbconnect();
	$sql = "UPDATE lunch_data SET thedate={$thedate}, rating={$rating}, spent={$spent}, comment={$notes}, publish=NOW() WHERE id={$the_id}";
	$result = mysql_query($sql) OR DIE ("<strong>ERROR</strong><br />{$sql}<br />".mysql_error());
	dbclose();
	header("Location: show.php?pid={$pid}");
	exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Nonzero1.0 by nodethirtythree design
http://www.nodethirtythree.com
missing in a maze

-->
<html>
<head>
<?php showHead(); ?>

<title>The Donger Lunch Report › Nothing Fancy</title>
</head>
<body id="data">

<div id="header">

<div id="header_inner" class="fluid">

	<div id="logo">
		<?php showLogo(); ?>

	</div>

	<div id="menu">
		<ul>
			<?php showNav(); ?>
		</ul>
	</div>

</div>
</div>

<div id="main">

<div id="main_inner" class="fluid">

	<div id="primaryContent_2columns">

		<div id="columnA_2columns">

			<h3>what did you eat today?</h3>

			<?php echo ($error) ? "<p class=\"error\">Form error</p>" : ""; ?>

			<form action="edit.php" method="post">
				<p>
					Where?<br /><?php echo $loc; ?>

				</p>

				<p>
					When?<br />
					<select name="month">
						<option value="">MM  </option>
						<?php
						$m = date("m");
						for ($i = 1; $i <= 12; $i++)
						{
							echo ($m == $i)
								? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
								: "<option value=\"{$i}\">{$i}</option>";
						}
						?>
					</select>
					/
					<select name="day">
						<option value="">DD  </option>
						<?php
						$d = date("d");
						for ($i = 1; $i <= 31; $i++)
						{
							echo ($d == $i)
								? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
								: "<option value=\"{$i}\">{$i}</option>";
						}
						?>
					</select>
					/
					<select name="year">
						<option value="">YYYY  </option>
						<?php
						$y = date("Y");
						for ($i = 2005; $i <= $y; $i++)
						{
							echo ($y == $i)
								? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
								: "<option value=\"{$i}\">{$i}</option>";
						}
						?>
					</select>
					M/D/YYYY
				</p>

				<p>
					How good was it?<br />
					<select name="rating">
						<option value="">N/A  </option>
						<?php
						for ($i = 100; $i >= 1; $i--)
						{
							echo ($i == $rating)
								? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
								: "<option value=\"{$i}\">{$i}</option>";
						}
						?>
					</select>
				</p>

				<p>
					How much did you spend?<br />
					<select name="dollars">
						<option value="">Dollars  </option>
						<?php
						for ($i = 1; $i <= 50; $i++)
						{
							echo ($i == $price[0])
								? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
								: "<option value=\"{$i}\">{$i}</option>";
						}
						?>
					</select>
					.
					<select name="cents">
						<option value="">Cents  </option>
						<?php
						for ($i = 1; $i <= 99; $i++)
						{
							if ($i < 10)
							{
								$temp = "0{$i}";
								echo ($temp == $price[1])
									? "<option selected=\"selected\" value=\"{$temp}\">{$temp}</option>"
									: "<option value=\"{$temp}\">{$temp}</option>";
							}
							else
							{
								echo ($i == $price[1])
									? "<option selected=\"selected\" value=\"{$i}\">{$i}</option>"
									: "<option value=\"{$i}\">{$i}</option>";
							}
						}
						?>
					</select>
					$XX.XX USD
				</p>


				<p>
					Any comments?<br />
					<textarea name="comment" rows="4" cols="30"><?php echo myEscape($comment); ?></textarea>
					<br />max 255 characters
				</p>

				<p>
					<input type="hidden" name="the_id" value="<?php echo $the_id; ?>" />
					<input type="hidden" name="pid" value="<?php echo $pid; ?>" />
					<input type="submit" name="Submit" value="Submit" /> -
					<input type="reset" name="Reset" value="Reset" />
				</p>
			</form>

			<h3>would you like to backup data?</h3>

			<p>
				It will export to a .xls file.
			</p>

			<p>
				<a href="exportdata.php">Click me</a> to export data table.
			</p>

			<p>
				<a href="exportloc.php">Click me</a> to export location table.
			</p>

			<p>
				<a href="#" title="Back to the top">↑ top</a>
			</p>

		</div>

	</div>

	<div id="secondaryContent_2columns">

		<div id="columnC_2columns">

			<h4><span>Recent</span> Entries</h4>
			<ul class="links">
				<?php showRecent(); ?>
			</ul>

		</div>

	</div>

	<br class="clear" />

</div>

</div>

<div id="footer" class="fluid">
<?php showFooter(); ?>
</div>

</body>
</html>

Link to comment
Share on other sites

here is your problem

if ($_POST["Submit"] == "Submit") {
foreach ($_POST as $key => $val) {
	$_POST[$key] = myEscape($val);

you never close the foreach

change that section to

if ($_POST["Submit"] == "Submit") {
foreach ($_POST as $key => $val) {
	$_POST[$key] = myEscape($val);
}

unexpected $end normally means there is a brace still open

 

Scott.

 

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.