Click here to Skip to main content
15,892,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a site with an account, set up to phpmyadmin database.

I would like to be able to have the user upload an image associated with their account.
I am not too sure how to do this. My guess would be to have a column in the database that somehow references the picture?

Could i please get some help with examples showing me ways i can do this, i would love to learn how so i can do this in the future and how a user can be linked up with their image.

PHP
//take user input and make sure there are no "/"s in it 
					$username = $mysqli->escape_string($username);
				    
					 $sql = "SELECT COUNT(*) FROM users WHERE email = '$username'";//username
				      if ($result = $mysqli->query($sql)) 
				      {
				        $row = $result->fetch_array();
				        // if yes, fetch the encrypted password
				        if ($row[0] == 1) 
				        {
				          $sql = "SELECT password FROM users WHERE email = '$username'"; //username
						         
				          if ($result = $mysqli->query($sql)) 
				          {
				            $row = $result->fetch_object();    
				
				            $hash = $row->password;
							
							
							if (crypt($password, $hash) == $hash) 
				            {              
				              echo 'Your login credentials were successfully verified.'; 
							  
							  session_start();
							  $_SESSION['username'] = $username;
							  
							  $queryLogin = "SELECT * FROM users WHERE email = '{$_SESSION["username"]}' ";
							  $myResult = $mysqli->query($queryLogin);
							  $myRow = $myResult->fetch_array();
							  
							  $fname = $row["firstName"];
							  
							  
							  echo "<input type=\"text\" name=\"xyz\" value='<?php echo $fname; ?>' >";
							   
				            /*
							//<input type="text" name="xyz" value=<?php echo $val; 
							//echo "<input type=\"text\" name=\"xyz\" value='$val'>";
							 *<input type="text" name="text1" value="<?php echo $row["usr_password"]; ?>">
							 * 
							 * 
							 * 
							 * 		$id = $_GET['id'];
 								 	$sql="select * from Doctor where DocID='$id'";
									$result=mysql_query($sql);
									$row=mysql_fetch_array($result);
							 * 
							 *   <input type = "text" name = "DocName" value = "<? echo $row['DocName']; ?>" >
							 * */
							 // UPDATE tablename SET columnName $variable etc... WHERE id = $id;
							
							
							/*
							 * $Name=$_POST['unames'];
								$data=mysql_query("SELECT * FROM tbl_sample where Name='$Name'");

								$info=mysql_fetch_array($data);
								while($info=mysql_fetch_array($data)){}
							 */
							} 
				            else 
				            {
				              echo 'You entered an incorrect password.';            
				            }
				          }
//put password field in a variable.
				if (empty($_POST['password'])) 
	      		{
		        	echo 'ERROR: Please enter a valid password';
	    	    	$inputError = true;        
	    		} 
	    		else 
	      		{	//properly escape the field
	      			$password = $mysqli->escape_string($_POST['password']);
					
	    		}
				//passwords must match [password]==[password2]
				if (empty($_POST['password2']))
				{
					echo 'ERROR: Passwords must match!!!';
					$inputError = true;
				}
				else if ($_POST['password'] == $_POST['password2'])
				{
					//success
					$salt = crypt($password);
				}
				else
				{
					echo 'ERROR: Passwords must match!!!';
					$inputError = true;
				}
				if($inputError != true)
				{
					//insert query
					$sqlInsertQuery = "INSERT INTO users (address, email, firstName, lastName, password)		
					VALUES ('$address', '$email', '$fName', '$lName', '$salt')";
					
$id = $mysqli->insert_id;
					$sql2 = "INSERT INTO usersPhone (ID, homePhone) VALUES ($id, '$phone')";
Posted
Comments
Richard Deeming 24-Oct-14 8:16am    
If you've got the user's email address, it might be easier to use Gravatar.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900