Page 1 of 1

User not found in script :/

Posted: Mon Dec 17, 2012 5:12 pm
by dalle1996
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
<?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>
				";
			?>

Re: User not found in script :/

Posted: Mon Dec 17, 2012 6:32 pm
by ExtremeGaming
$username will return the value of true because you are using isset(); Remove that and give it a try.

Re: User not found in script :/

Posted: Tue Dec 18, 2012 6:29 am
by dalle1996
Yes thanks, it worked (Y)