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.
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
error no. 3:
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:
<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()
{
$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>