Click here to Skip to main content
14,550,260 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi

have this error and i need to know what and where did i gone ary, is it empty, do i have to use and isset to fix it. the error is this

Parse error: syntax error, unexpected '$num' (T_VARIABLE) in C:


any help would be appreciated. here is my codes.

What I have tried:

<pre><?php

		
		$db_host='localhost';
		$db_username='root';
		$db_password="";
		$con=mysqli_connect($db_host,$db_username, $db_password) or die (mysqli_connect_error());
		
		mysqli_select_db($con, 'food') or die (mysqli_error($con));
		if(isset($_POST['submit']) && isset($_GET['img_id']))
		{
			$sql= "SELECT * FROM tbl_images  WHERE img_id={$img_id}";
			$result=mysqli_query($con, $sql) or die("Error:" .mysql_error($con));
			$rowcount=mysqli_num_rows($result);
		}
		
			
?>
<html>
<body>	
		<form  method="post" enctype="multipart/form-data" >
			<br/>
				<input type="file" name="image">
				<br/><br/>
				<input type="submit" name="submit" value="upload">
		</form>
			
		
<?php		
		if(isset($_POST['submit'])&& isset($_FILES['file']))
		{
			if(getimagesize($_FILES['image']['tmp_name'])== false)
			{
				echo "Please select an image";
			}
			else
			{
				
				$name=addslashes($_FILES['image']['name']);
				$image=base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));				
				saveimage($name, $image);
			}			
		}
	
	function saveimage($name,$image)
	{
			$con = mysqli_connect($db_host, $db_username, $db_password,"tbl_images");			
			$sql="INSERT INTO tbl_images(name,image) value('$name, '$image')";
			$query=mysqli_query($con, $sql);
			
			if($query)
			{
				echo "Success";
			}
			else
			{
				echo "not Upload";
			}
		
	}
	displayimage();	
	function displayimage()//this function is used to display the images from the db
	{
		$con = mysqli_connect($db_host, $db_username, $db_password,"tbl_images");			
		$sql="SELECT * FROM tbl_images";
		$query=mysqli_query($con, $sql);
		$query=mysqli_query($con, $query)
		$num=mysqli_num_rows($query);					
		for($i=0; $i<$num; $i++)
		{
			$result=mysqli_fetch_array($query);
			$img=$result['image'];
			echo'<img src="data:image;base64, '.$img. '">';
		}
		mysqli_close($con);
	}
			
?>		
		
</body>
</html>
Posted
Updated 26-May-18 11:08am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try
$query=mysqli_query($con, $query); // The semicolumn was missing here
$num=mysqli_num_rows($query);
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

$query=mysqli_query($con, $query)              <<<<<<<<<<<<<<< you are missing a semicolon here
    $num=mysqli_num_rows($query);
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

I have corrected the error that you have pointed out to me and now I am getting these errors.
error no. 1:
Warning: mysqli_connect(): (HY000/1049): Unknown database 'tbl_images' in C:\wamp64\www\luana_itec244\php\dashboard.php on line 68


error no. 2;
Notice: Undefined variable: query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70


error no. 3.
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70


error no.4:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp64\www\luana_itec244\php\dashboard.php on line 71


error no. 5:
Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in C:\wamp64\www\luana_itec244\php\dashboard.php on line 78
   
v3
Comments
Patrice T 26-May-18 17:12pm
   
Use Improve question to update your question.
So that everyone can pay attention to this information.
Update code too.
And delete this non solution.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100