Well, i am doing an avatar upload for profile but somehow, it always says that the user is not found and i have no idea why..
Here is my code:
I splitted it up so it will echo out the image with the first script and echo out the users image in the second script
[syntax=php]<?php
$username = isset($_SESSION['username']);
$query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
if (mysql_num_rows($query)==0)
die("User not found!");
else
{
$row = mysql_fetch_array($query);
$location = $row['profile'];
echo "<img src='$location'>";
}
?>
<?php
isset($_SESSION['username']);
$username = $_SESSION['username'];
if (isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name) {
$location = "images/$name";
move_uploaded_file($tmp_name,"images/profile/".$name);
$query = mysql_query("UPDATE `users` SET profile='$location' WHERE `username`='$username'");
die("Your images have been has been uploaded!");
} else die("Please select a file!");
}
echo "Upload your image:
<div class='profile'>
<form action='' method='post' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload!'>
</form>
</div>
";
?>[/syntax]
User not found in script :/
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: User not found in script :/
$username will return the value of true because you are using isset(); Remove that and give it a try.
<?php while(!$succeed = try()); ?>
Re: User not found in script :/
Yes thanks, it worked (Y)