Click here to Skip to main content
15,909,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I have since corrected the error that you guys have pointed out to me but now I have three more errors and i have no idea how to fix it. been searching the net for something similiar but to no avail. here are the errors. it is the same codes.

error no1.
PHP
Notice: Undefined variable: query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70


error no 2:
PHP
Warning: mysqli_query(): Empty query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70


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


this project has to be handed in tomorrow so you know, it is a whole night for me. any help would be greatly appreciated. here i what I have. can someone tell me how do i get to insert and display images in my database, have tried everything, am now ran out of ideas

What I have tried:

PHP
<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)//this function is saving the images to the db
	{
			$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 will be used to display the images from the db
	{
		$db_host='localhost';
		$db_username='root';
		$db_password="";
		
		$con = mysqli_connect($db_host, $db_username, $db_password);			
		$sql="SELECT * FROM tbl_images";		
		$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 18:00pm

1 solution

Quote:
error no1: Notice: Undefined variable: query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70
error no 2 : Warning: mysqli_query(): Empty query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70

Messages are pretty clear
Just look at the code
PHP
$sql="SELECT * FROM tbl_images";
$query=mysqli_query($con, $query); // line 70 here

What is the name of the variable containing the query ?
Try
PHP
$sql="SELECT * FROM tbl_images";
$query=mysqli_query($con, $sql); // line 70 here
 
Share this answer
 

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



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