I'm getting this error and I can't figure out why:
"Parse error: syntax error, unexpected $end in C:\Program Files\IndigoPerl\apache\htdocs\process_menu2.php on line 160"
thanks :)
<?php
echo '<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h3>Uploading file...</h3>';
// Set up the database connection.
require_once ('mysqli_connect.php');
//if name selected from drop down box
if (isset($_POST['product_name']))
{
if ($_FILES['filename']['error'] > 0)
{
echo 'Problem: ';
switch ($_FILES['filename']['error'])
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
// put the file where we'd like it
$upfile = './images/'.$_FILES['filename']['name'];
if (is_uploaded_file($_FILES['filename']['tmp_name']))
{
if (!move_uploaded_file($_FILES['filename']['tmp_name'], $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: ';
echo $_FILES['filename']['name'];
exit;
}
echo '<p>File uploaded successfully<br><br>';
if (isset($_POST['description'])) {
$description = $_POST['description'];
} else {
$description = $_FILES['filename']['name'];
}
// show what was uploaded
echo '<p>Preview of uploaded file:<br><hr>';
echo "<a href='$upfile'>$description</a>";
echo '<br><hr>';
echo '</body></html>';
// add new sandwich
$product_name = $_POST['product_name'];
$product_description = $_POST['product_description'];
$price = $_POST['price'];
$query = "INSERT INTO products (product_name, product_description, price)
VALUES ('$product_name', '$product_description', '$price')";
$result = mysqli_query ($dbc, $query);
$productid = mysqli_insert_id($dbc);
$origin = $_POST['origin'];
$query = "INSERT INTO origins (origin, productid) VALUES ('$origin', '$productid')";
$result = mysqli_query ($dbc, $query);
$imagename = $_POST['image_name'];
$query = "INSERT INTO images (productid, image_name) VALUES ('$productid', '$imagename')";
$result = mysqli_query ($dbc, $query);
echo 'Productid: ' . $productid . ' ' . ' Product Name: ' . $product_name . ' ' . ' Product Description: ' . $product_description . ' ' . ' Image Name: ' .
$imagename . ' Origin: ' . $origin . ' Price: ' . $price . '<br>';
}
else
{
// update product_name selected
$product_id = $_POST[product_id];
// if description box not empty
if (!empty($_POST['product_description']))
{
$product_description = $_POST['product_description'];
$query = "UPDATE products SET product_description='$product_description' WHERE product_name='$product_id'";
$result = mysqli_query ($dbc, $query);
echo '<p>Description updated</p>';
}
// if price box not empty
if (!empty($_POST['price']))
{
$price = $_POST['price'];
$query = "UPDATE products SET price='$price' WHERE product_name='$product_id'";
$result = mysqli_query ($dbc, $query);
echo '<p>Price updated</p>';
}
// if origin box not empty
if (!empty($_POST['origin']))
{
$origin = $_POST['origin'];
$query = "INSERT INTO origins (origin, productid) VALUES ('$origin', '$productid')";
$result = mysqli_query ($dbc, $query);
echo '<p>Origin updated</p>';
}
//if filename box is not empty
if (!empty($_POST['filename']))
{
$query = "UPDATE images SET image_name='$imagename' WHERE product_id='$product_id'";
if ($_FILES['filename']['error'] > 0)
{
echo 'Problem: ';
switch ($_FILES['filename']['error'])
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
// put the file where we'd like it
$upfile = './images/'.$_FILES['filename']['name'];
if (is_uploaded_file($_FILES['filename']['tmp_name']))
{
if (!move_uploaded_file($_FILES['filename']['tmp_name'], $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: ';
echo $_FILES['filename']['name'];
exit;
}
echo '<p>File uploaded successfully<br><br>';
if (isset($_POST['description'])) {
$description = $_POST['description'];
} else {
$description = $_FILES['filename']['name'];
}
// show what was uploaded
echo '<p>Preview of uploaded file:<br><hr>';
echo "<a href='$upfile'>$description</a>";
echo '<br><hr>';
echo '</body></html>';
$result = mysqli_query ($dbc, $query);
echo '<p>Image name updated</p>';
}
}
if ($result) { // If it ran OK.
echo '<p>Data has been entered successfully.</p>';
} else { // If it did not run OK.
echo '<p>Data has not been processed due to a system error.</p>';
}
?>