0

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>';

        }

?>
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

I didn't find anything wrong in your code, perhaps an extra brace is closed or need to close a brace in your script, double check by commenting out each if condition and switch statements.

0

Oops I may have copied the wrong one, here's the one with the error. Sorry!

<?php

echo '<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h3>Uploading file...</h3>';

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>';


// Set up the database connection.
require_once ('mysqli_connect.php');

    //if name selected from drop down box
	if (isset($_POST['product_name']))
	{
		if (isset($_POST['product_name']) && isset($_POST['product_description']) && isset($_POST['price']))
		{

		// 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);

		if (isset($_POST['origin']))
		{

			$origin = $_POST['origin'];

			$query = "INSERT INTO origins (origin, productid) VALUES ('$origin', '$productid')";

			$result = mysqli_query ($dbc, $query);
		}

		if (isset($_POST['filename']))
		{

			$imagename = $_POST['filename'];

			$query = "INSERT INTO images (productid, image_name) VALUES ('$productid', '$imagename')";

			$result = mysqli_query ($dbc, $query);
		}

		else
		{
			echo '<p>Error - All fields are required!</p>';
		}
	}
else
	{
			// update product_name selected

			if (isset($_POST['product_id']) && isset($_POST['product_description']) && isset($_POST['price']))
			{

				$product_id = $_POST[product_id];
				$product_description = $_POST['product_description'];
				$price = $_POST['price'];

				$query = "UPDATE products SET product_description='$product_description', price='$price',
									   WHERE product_id='$product_id'";

				$result = mysqli_query ($dbc, $query);

				if (isset($_POST['origin']))
				{

					$origin = $_POST['origin'];

					$query = "INSERT INTO origins (origin, productid) VALUES ('$origin', '$productid')";

					$result = mysqli_query ($dbc, $query);
				}

				if (isset($_POST['filename']))
				{

					$imagename = $_POST['filename'];

					$query = "UPDATE images SET image_name='$imagename' WHERE product_id='$product_id'";

					$result = mysqli_query ($dbc, $query);
				}
			}

			else
			{
				echo '<p>Error!</p>';
			}

	}


echo 'Productid: ' . $productid . ' ' . ' Product Name: ' . $product_name . ' ' . ' Product Description: ' . $product_description . ' ' . ' Image Name: ' .
$imagename . ' Origin: ' . $origin . ' Price: ' . $price . '<br>';

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>';

        }

?>
0

You missing a brace for an if statement

if (isset($_POST['product_name']))
{
	if (isset($_POST['product_name']) && isset($_POST['product_description']) && isset($_POST['price']))
	{
		// 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);

		if (isset($_POST['origin']))
		{

			$origin = $_POST['origin'];

			$query = "INSERT INTO origins (origin, productid) VALUES ('$origin', '$productid')";

			$result = mysqli_query ($dbc, $query);
		}

		if (isset($_POST['filename']))
		{

			$imagename = $_POST['filename'];

			$query = "INSERT INTO images (productid, image_name) VALUES ('$productid', '$imagename')";

			$result = mysqli_query ($dbc, $query);
		}

		else
		{
			echo '<p>Error - All fields are required!</p>';
		}
}
[B]}[/B] //This is the brace must be closed

Hope this solve!

Edited by rajarajan07: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.