i've already searched but i got more confused when new codes appears in my sight again (cuz im just a newbie)
So, what I want to is, when the user successfully uploads the image(upload.php), it will be viewed before continuing into the next step (view.php).
index.php
<html>
<body bgcolor="black" style="color:gray">
<form action="index.php" method=get>
<h1 align="center" style="color:gray" >Welcome to this simple application</h1>
<?php
//This will start a session
session_start();
$username = isset($_SESSION['username']);
$password = isset($_SESSION['password']);
$imagelocation = isset($_GET['imagelocation']);
//Check do we have username and password
if(!$username && !$password){
echo "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
}
else{
$connect = mysql_connect("localhost", "root", "");
if(!$connect){
die(mysql_error());
}
$select_db = mysql_select_db("test", $connect);
if(!$select_db){
die(mysql_error());
}
echo "Welcome ".$username." (<a href=logout.php>Logout</a>)<br />papakta ng web ang dpat ifillup bago mag homepage. pedeng may skip.<br />";
if ($imagelocation==NULL){
echo "<a href=upload.php>1.UPLOAD an IMAGE</a>";
}
}
?>
</html>
upload.php
<?php
include("connect.php");
$username= isset($_SESSION['username']);
if (isset($_POST['submit']))
{
//get file attributes
$name=$_FILES['myfile']['name'];
$tmp_name= $_FILES['myfile']['tmp_name'];
if ($name)
{
//start now
$location = "avatars/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
die("Your avatar has been uploaded! <a href='view.php'>HOME</a>");
}
else die ("Please select a file!");
}
echo "Welcome, ".$username."!<p>";
echo "Upload your image:
<form action='upload.php' method='POST' enctype='multipart/form-data'>
File:<input type='file' name='myfile'><input type='submit' name='submit' value='Upload'>
</form>";
?>
view.php
<?php
include("connect.php");
$username = $_SESSION['username'];
$imagelocation = isset($_SESSION['imagelocation']);
$query=mysql_query("SELECT * FROM users WHERE imagelocation='$imagelocation'");
if (mysql_num_rows($query)==0)
die("User not found! ");
else
{
$row = mysql_fetch_assoc($query);
$location = "avatars/$name";
echo "<img src='$location' width='100' height='100'>";
}
?>
However, when the user uploads a picture, then it will be proceed to view.php, the picture doesn't show up.
I have a folder named avatars, and when the user uploads, the picture is there.
I'm really thankful for those who'll helped me.