Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is another question my assignment. I have been trying to store, retrieve and display an image into my db(it is one of the requirement for this assignment) and i am stuck on this error, been research to see what is the error but i think i have covered all the bases but i guess I didnt because it has an error somewhere but cant see it.

here is my code for it


I checked for missing semi-colon, missing brackets, missing inverted commas but cud not come up with anything that i can see so maybe a third can see what I cannot, many thanks in return and here is the error

Parse error: syntax error, unexpected '{', expecting '(' in C:\wamp64\www\Taylor_Luana_ITEC244_Assignment1\php\upload_pic.php on line 72


What I have tried:

PHP
<pre><?php
		error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title> Welcome </title>
		<link rel="stylesheet" type="text/css" href="../css/stylesheet.css" />
	</head>
	<body>
		<div id="container">
			
			<div id="header">
				<div  id="banner">
					<img src="../images/header.jpg" alt="header" />
				</div>
			</div>
			<div id="navbar">
				<ul>
				
					<li><a  href="../index.html" id="tlinks" class="toplinks">Homepage</a></li>
					<li><a  href="featureNaturalWonders.html" id="thold" class="toplinks">Feature Natural Wonders</a></li>
					<li><a  href="contact.html" id="linkhold" class="toplinks" >Contact Us</a></li>
					<li><a  href="register_user.html" id="phold" class="toplinks"> Sign Up</a></li>
					<li><a  href="login_user.html" id="loglinks"class="toplinks"> Login</a></li>
					<li><a  href="aboutus.html" id="panlinks" class="toplinks"> About Us</a></li>
					 
				</ul>	
					<form method="post" id="search"   action="" >						
						<input type="text" name="search" value=""/>
						<input type="submit" value="Search"/>												
					</form>				
									
			</div>	
			
			
			<div id="contentArea">
			
				<?php
				
					include'$db_server.php';
					
					if(isset($_POST['submitBtn']) &&!empty($_POST['submitBtn']))
					{
						if(isset($_FILES['uploadFile']['name']) &&!empty($_FILES['uploadFile']['name']))
						{
							//this code will allowed the file type to be uploaded
							$allowed_extension=array("jpg","jpeg","png","gif");
							
							//file extension
							$ext=strtolower(pathinfo($_FILES["uploadFile"]["name"], PATHINFO_EXTENSION));
							
							//check extension
							if(in_array($ext,$allowed_extension))
							{
								//convert image to base64
							    base64_encode(file_get_contents($_FILES['uploadFile']['temp_name']));
								$encoded_image='data:image/'.$ext.';base64,'.$encoded_image;
								$query = "insert into `images` set `encoded_image` = '".$encoded_image."'";
								mysqli_query ($conn,$query);
								echo"File name:".$_FILES['uploadFile']['name'];
								echo "<br>";
								
								if(mysql_affected_rows($conn)>0)
								{
									echo"status:Uploaded";
									
									$last_insert_id = mysqli_insert_id($conn);
									
								}
								else
								{
									echo "Status: failed to Upload";
								}
								else
								{
									echo "File not allowed";
								}
							}
							
						}
					}
				
					
				?>
				
				<?php
					
					//ths is retrieving the image from the db
					if($last_insert_id)
					{
						$query = "SELECT 'encoded_image' from visitors WHERE 'id'=".$last_insert_id;
						$result=mysqli_query($conn,$query);
						
						
						if(mysqli_num_rows($result)== 1)
						{
							$row=mysqli_fetch_object($result);
							
							echo "<br><br>";
							
							echo '<img src="'.$row->encoded_image.'" width="390">';
						}
					}
									<!---www.mitrajit.com->

					?>
			</div>

	</body>
</html>
Posted
Updated 19-Apr-19 4:34am
Comments
#realJSOP 19-Apr-19 8:32am    
Which line is line 72?

if I have to guess, I think the trouble lines are in this block. Notice that there are duplicate else statements. Usually PHP will raise "unexpected T_ELSE..." error

PHP
if(mysql_affected_rows($conn)>0)
    {
    	echo"status:Uploaded";
    	
    	$last_insert_id = mysqli_insert_id($conn);
    	
    }
    else
    {
    	echo "Status: failed to Upload";
    }
    else
    {
    	echo "File not allowed";
    }
 
Share this answer
 
@Bryan Tan

yes the error is the both else, sorry I forgot to point out the errors in my question
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900