Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Help me on display user profile image and information

    Hi,
    Please i really need help on displaying and setting up user profile picture and information from database.It given me headache for days
    It given me errors and not able to update.Here is the files

    Here is the sql file
    Code:
    -- phpMyAdmin SQL Dump
    -- version 3.3.9
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Feb 22, 2012 at 01:19 PM
    -- Server version: 5.5.8
    -- PHP Version: 5.3.5
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    
    --
    -- Database: `kpoly`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `profile_info`
    --
    
    CREATE TABLE IF NOT EXISTS `profile_info` (
      `profile_id` int(11) NOT NULL AUTO_INCREMENT,
      `user_id` int(11) NOT NULL,
      `location` varchar(200) NOT NULL,
      `contact` varchar(200) NOT NULL,
      `project` varchar(200) NOT NULL,
      `aboutme` text NOT NULL,
      PRIMARY KEY (`profile_id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    --
    -- Dumping data for table `profile_info`
    --
    
    INSERT INTO `profile_info` (`profile_id`, `user_id`, `location`, `contact`, `project`, `aboutme`) VALUES
    (1, 2, 'tarkwa and accra', 'ot.clement@gmail.com', 'Website development project on march 2012', 'I am a web deveoper');

    Here is the user.inc.php file

    Now in TABLE profile_info, the field user_id is taken from TABLE users.I did that to refer to the current user login.
    PHP Code:
    <?php
     
    function user_infor($profile_id){
        
    $profile_id=(int)$profile_id;
        
    $sql="SELECT
              `profile_info`.`user_id`,
              `profile_info`.`profile_id`,
              `profile_info`.`location` AS `locations`,
              `profile_info`.`contact` AS `contacts`,
              `profile_info`.`project` AS `projects`,
              `profile_info`.`aboutme` AS `about`
              FROM `profile_info` WHERE 
               `profile_info`.`profile_id`='$profile_id' AND `user_id`='"
    .$_SESSION['user_id']."'";
              
              
    $result=mysql_query($sql);
              
           
    $informysql_fetch_assoc($result);
           
    //this the path of the image and check if the file exist ,if not we set up a defaut image
           
    $infor['avatar']=(file_exists("user_avatars/{$infor['user_id']}.jpg")) ?"user_avatars/{$infor['user_id']}.jpg" "user_avatars/default.jpg";

        return 
    $infor;
    }

      function 
    update($location,$contact,$project,$aboutme,$avatar){
        
    $location=mysql_real_escape_string($location);
        
    $contact=mysql_real_escape_string($contact);
        
    $project=mysql_real_escape_string($project);
        
    $aboutme=mysql_real_escape_string($aboutme);
        
        
    //checking to see if the avatar exist
        
    if(file_exists($avatar)){
         
    //weresie the image
         
    $src_size=getimagesize($avatar);//getting the size of the image and is in array means storing $avatar in an array
         
         //these are the image formate to upload
         
    if($src_size['mime']==='image/jpeg'){
          
    $src_img=imagecreatefromjpeg($avatar);
         }else if(
    $src_size['mime']==='image/png'){
          
    $src_img=imagecreatefrompng($avatar);
         }else if(
    $src_size['mine']==='image/gif'){
          
    $src_img=imagecreatefromgif($avatar);
         }else{
           
    $src_img=false//if not $src_img will not process
         
    }

         if(
    $src_img!==false){ //now if $src_img is not falls ,then we resize the image to upload
           
    $thumb_width=100//thus width of the thumnail

           
    if($src_size[0]<=$thumb_width){ //here i'm cheking if the image size is less or equal 2 thumb width,then no need to resize
             
    $thumb=$src_img;
           }else{

             
    $new_size[0]=$thumb_width//width of new image
             
    $new_size[1]= ($src_size[1] / $src_size[0])*$thumb_width//height but divide the    height of $src_size by width
           
            
    $thumb=imagecreatetruecolor($new_size[0],$new_size[1]);//this is resizing it to fit
            
    imagecopyresampled($thumb,$src_img,0,0,0,0,$new_size[0],$new_size[1],$src_size[0],$src_size[1]);
           }
           
           
    imagejpeg($thumb,"user_avatars/{$_SESSION['user_id']}.jpg"); //finally create the thumb
         
    }
        }

         
    mysql_query("UPDATE `profile_info` SET
                   `location`='$location',
                   `contact`='$contact',
                   `project`='$project',
                   `aboutme`='$aboutme' WHERE `user_id`='"
    .$_SESSION['user_id']."'");
      }
    ?>

    Here is the edit_profile.php file
    PHP Code:
    <?php
     
    include 'func/init.php';
      include 
    'func/user.inc.php';
      include 
    'func/user.php';
      include 
    'template/header_all.php';
      

    ?>

    <div id="leftnav2">

    <?php
    //welcoming user here
    if(logged_in()){
    $f_name=user_data('firstname');
    $l_name=user_data('lastname');
    echo 
    'Welcome '.' '.$f_name.' '.$l_name;
    }else{
    exit(
    'You dont have permission to access this page?');
    }
    ?>
    </div>

    <div id="rightnav2">
    <p>I am proud to be a web developre</p>
     </div>


    <div id="content2">
    <?php
     
    //this line helps to get the infor
      //checking the form
      
      
    if(isset($_POST['location'],$_POST['contact'],$_POST['project'],$_POST['aboutme'])){
       
       
    $error=array();;
       
    $location=htmlentities($_POST['location']);
       
    $contact=htmlentities($_POST['contact']);
       
    $project=htmlentities($_POST['project']);
       
    $aboutme=htmlentities($_POST['aboutme']);
       
       if(empty(
    $location)){
        
    $error[]= 'Location is required';
       }
       
       if(empty(
    $contact)){
         
    $error[]= 'Contact is Required';
       }
       
       if(empty(
    $project)){
       
    $error[]= 'Project is required';
       }
       
      if(empty(
    $aboutme)){
       
    $error[]= 'About me is required';
       }


       if(
    $location>200 || $contact>200 || $project>200){
        
    $error[]= 'Location or Contact or Project contain too more characters';
       }
       
       
    //here if the user does not upload image, no error given..it is optional.
       
    if(empty($_FILES['avatar']['tmp_name'])===false){
         
    $avatar=$_FILES['avatar']['tmp_name'];
        
    $image_ext=end(explode('.',$_FILES['avatar']['name']));  //to find the file ext

        //checking the ext to be uploaded
        
    if(in_array(strtolower($image_ext),array('jpg','jpeg','gif','png'))===false){
         
    $error[]='You must upload image only';
        }

       }


       if(!empty(
    $error)){
        echo 
    '<ul><li>'.implode('</li><li>',$error).'</li></ul>';
       }else
        
    //if no errors update
       
    {
        
    update($location,$contact,$project,$aboutme,@$avatar);
        echo 
    'Your profile have been updated';
       }
      }
    ?>






    <form action="" method="POST" enctype="multipart/form-data">
     Location: <br> <input type="text" name="location" maxlength="200" value=""><br>
      Contact:<br><input type="text" name="contact" maxlength="200" value=""> <br>
       Project:<br><input type="text" name="project" maxlength="200" value=""> <br>
      
      About Me: <br> <textarea name="aboutme" cols="30" rows="5"></textarea><br>
       Choose Image: <br><input type="file" name="avatar"><br/>
      <input type="submit" value="Update">

    </form>

    </div>
    <?php
    include 'template/footer.php';

    ?>



    Here is the profile.php file
    PHP Code:
    <?php
      
    include 'func/init.php';
      include 
    'func/user.inc.php';
      include 
    'func/user.php';
      include 
    'template/header_all.php';
    ?>




    <div id="leftnav">
    <?php
      
    //welcoming user
    if(logged_in()){
    $f_name=user_data('firstname');
    $l_name=user_data('lastname');
    echo 
    'Welcome '.' '.$f_name.' '.$l_name;
    }else{
    exit(
    'You dont have permission to access this page?');
    }
    ?>


    <?php
     
    //displaying user profile here
      
    $user_infor=user_infor($_SESSION['user_id']);
       
       if(
    $user_infor===false){
        echo 
    'User does not exist';
       } else{
       
    ?>

     <img src="<?php echo $user_infor['avatar']; ?>" alt="Profile_Image" />

    <p>Location: <?php echo $user_infor['locations']; ?> </p>
    <p>Contact:  <?php echo $user_infor['contacts']; ?></p>
    <p>Project:  <?php echo $user_infor['projects']; ?></p>
    <p>About Me:  <?php echo $user_infor['about']; ?></p>

       <?php
       
    }
       
    ?>
    </div>






     
    <?php
    include 'template/footer.php';

    ?>

    Now when i go to profile.php page ,it gives me this errors
    Code:
    Location:
    ( ! ) Notice: Undefined index: locations in C:\wamp\www\k_poly\profile.php on line 35
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0037	374760	{main}( )	..\profile.php:0
    
    Contact:
    ( ! ) Notice: Undefined index: contacts in C:\wamp\www\k_poly\profile.php on line 36
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0037	374760	{main}( )	..\profile.php:0
    
    Project:
    ( ! ) Notice: Undefined index: projects in C:\wamp\www\k_poly\profile.php on line 37
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0037	374760	{main}( )	..\profile.php:0
    
    About Me:
    ( ! ) Notice: Undefined index: about in C:\wamp\www\k_poly\profile.php on line 38
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0037	374760	{main}( )	..\profile.php:0

    Also the edit does not update when the form is field and submitted.
    Please any help will be highly appreciated.

    Thanks
    Clement Osei

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,092
    Thanks
    23
    Thanked 594 Times in 593 Posts
    The first command before anything is outputted is session_start(); You don't have that anywhere in you code. Put it in every php page and see what happens.

    reference http://php.net/manual/en/function.session-start.php

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Unless you already have it in one of the included scripts ...

    <?php
    include 'func/init.php';
    include 'func/user.inc.php';
    include 'func/user.php';
    include 'template/header_all.php';
    ?>

    If you have it twice, you get a "session already started" error.

    .

  • #4
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi ,
    Thanks for your time.
    actually i have session_start() in the func/init.php file but i am wondering why it given me errors.

    Well i'm still trying ,so any help from you ,i will congratulate you of that.

    Thanks
    Clement Osei

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Is it all working except for those notices?
    By that I mean ... even though you get notices, are there values where they are supposed to be?

  • #6
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Sir,

    Thanks much for your time on me.

    Actually , i did not insert the profile picture in the database.
    NOW when under the profile picture uploaded by the using using the edit page.

    There also information the user need to provide .like contact ,location,about me, need to display on the profile but in this case information do not retrieve from the database.

    I don't know either is the query which i have problem with it.

    But i'm still working on it ,but looking for any point out mistakes

    Thanks much
    Clement Osei

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Use your webhost's control panel to access your MySQL database and manually
    browse the tables to see what has been inserted in them. Keep that
    MySQL editor open in a separate window while you troubleshoot (very handy).

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    Quote Originally Posted by mlseim View Post
    Use your webhost's control panel to access your MySQL database and manually
    browse the tables to see what has been inserted in them. Keep that
    MySQL editor open in a separate window while you troubleshoot (very handy).
    Just to extend on this idea, if your host allows remote connections to your MYSQL database get HeidiSQL and connect with that, easier than PHPmyadmin.

    As for the warnings, you are looking for 'locations' and the field value is actually called 'location' etc. Make sure the mysql column names match the field values you are looking for in PHP.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •