Hi. So I read the several pages of the sticky parse error, unexpected $end thread, which basically said to make sure you have the correct amount of brackets and to use the full <?php opening tags, which I am doing.
I've got a relatively short script here with which I am experiencing an unexpected $end error. I am 99% certain my brackets are all correct,and I can not for the life of me figure out what is causing the problem here. I'm probably just missing something...
<?php
/* This script is designed as the action script for a form on
another page, using the GET method. It can also be used with
only one of the variables set, $_GET["cid"], in which case
the script asks you for the other variable. The purpose is
to update the amount of a chemical in a chemical database. */
//Checks to see if login cookie is good, kicks out bad cookies and does nothing if cookie is good
{
if (isset($_COOKIE["login"]))
{
if ($_COOKIE["login"]!="sensitive data removed")
header( 'Location: index.php' ) ;
}
else
header( 'Location: index.php' ) ;
}
// Connects to database here and prepares tables based on GET variables.
$con = mysql_connect("myhost","myusername","mypassword");
mysql_select_db("mydatabase", $con);
$result4 = mysql_query("SELECT * FROM chem_inventory WHERE cid='" . $_GET["cid"] . "'");
$row4 = mysql_fetch_array($result4);
$result5 = mysql_query("SELECT * FROM chem_data WHERE sid='" . $row4['sid'] . "'");
$row5 = mysql_fetch_array($result5);
/* if: updates table after asking for the missing variable, obtained by posting from the form below.
elseif: Takes various actions if $_GET variables exist.
{
if: if the amount variable is set, updates the table and redirects to db.php.
else: asks you for the missing amount variable, submits back to this script using post.
}
else: if no $_GET variables are provided at all, redirects you back to db.php to obatin them. */
if (!empty($_POST))
{
mysql_query("UPDATE chem_inventory SET amount = '" . $_POST["amount"] . "' WHERE cid = '" . $_POST["cid"] . "'");
header( 'Location: db.php?sid=" . $_POST["sid"] . "' ) ;
}
elseif (!empty($_GET))
{
if (isset($_GET["a"]))
{
mysql_query("UPDATE chem_inventory SET amount = '" . $_GET["a"] . "' WHERE cid = '" . $_GET["cid"] . "'");
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = "db.php?sid=" . $row4['sid'] . "";
header("Location: http://$host$uri/$extra");
}
else
{
$cName = $row5['name'];
$cid = $_GET["cid"];
echo <<<END
<html>
<body>
<div align="center">
<br>
<br>
<h4>Update Chemical: $cName </h4>
<br>
<form action="amountUpdate.php" method="get">
New Amount:
<input type="text" name="a" id="amount">
<br>
<input type="submit" value="Update Amount">
<input type="hidden" name="cid" value="$cid" />
</form>
END;
}
}
else
{
header( 'Location: db.php' );
}
?>