hi all
presently am doing an assignment. for the past hour or have been experiencing one error to the next with it. it is website am doing where a user can register, login, view their profile etc.
one part of the assignment is where u have to insert and display images on the site using php.
I get thru in some aspect of the assignment concerning the inserting and displaying images. i cant get the images to display, dont know if there is something wrong with the code or what. I am currently getting this errors. have tried everything that I can think of. search on the net, got a few ideas, tried it out but nothing seem to be working. I have only 2 more day to finish this assignment. I am on crunch time here. so any solution would be greatly appreciated.
these are the two errors
error no. 1: Notice: Undefined variable: sql in C:\wamp64\www\luana_itec244\php\upload.php on line 22
error no. 2: Notice: Undefined variable: sql in C:\wamp64\www\luana_itec244\php\upload.php on line 22
they are both on the same line. here is my codes. I need some answers not people just viewing my questions and passing it str8. much thanks in advance.
<?php
session_start();
if(isset($_POST['submit']))
{
$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($_GET["img_id"]))
{
$sql="SELECT * FROM tbl_images WHERE img_id='$img_id'";
}
if(isset($_POST['submit']))
{
$result=mysqli_query($con,$sql) or die("Error:" .mysqli_error($con));
$rowcount=mysqli_num_rows($result);
}
if($rowcount >=1)
{
echo"<script type=\"text/javascript\";
alert('files not uploaded');
window.location=\"login.html\";
</script>";
}
else
{
//insert images into table
$sql = "INSERT INTO tbl_images
VALUES('img_id','name','image')";
if(mysqli_query($con, $sql))
{
mysqli_close($con);
header("location:dashboard.php");
}
else
{
echo "Error inserting images";
}
}
}
?>