User not found in script :/

Ask about a PHP problem here.
Post Reply
dalle1996
Posts: 8
Joined: Tue Dec 11, 2012 1:25 pm

User not found in script :/

Post 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>
				";
			?>
Image
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: User not found in script :/

Post by ExtremeGaming »

$username will return the value of true because you are using isset(); Remove that and give it a try.
<?php while(!$succeed = try()); ?>
dalle1996
Posts: 8
Joined: Tue Dec 11, 2012 1:25 pm

Re: User not found in script :/

Post by dalle1996 »

Yes thanks, it worked (Y)
Image
Post Reply