www.webdeveloper.com
Results 1 to 3 of 3

Thread: User account display data

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    User account display data

    Hi want to display some data once an user logged into their account, but right now my it displays all the records from one of my database table and some of them doesn't belong to the user. e.g logged in as user1 in the user1 account page you can find its own data and user2's and user3's as well. I don't want this I just want user1 account display its own data.
    Please help I am a beginner. Thanks

    This is in my user account page:
    PHP Code:
    <?php 
    session_start
    ();
    session_regenerate_id();
    if(
    $_SESSION['account_id'] == '')
    {
        
    header('location: registration.php');
        exit;
    }
    ?>
    PHP Code:
    <table border="1">
    <?php

    //include database connection
    $con=mysqli_connect("localhost","","","");//database connection
     
     
    $query "select account_id, goalName, goal_id, gdescription, progress from goal where username =".$_SESSION['account_id']; 
     
    //execute the query
    $resultmysqli_query($con,$query);
    while(
    $row mysqli_fetch_assoc($result)){
    ?>
    <tr>
    <td><?php echo $row['goalName'] ; ?></td>
    <td><?php echo $row['gdescription'] ; ?></td>
    <td><?php echo $row['progress'] ; ?></td>
    <td><a href="deletegoal.php<?php echo '?goal_id='.$row['goal_id']; ?>">delete</a></td>
    <td><a href="editGoal.php<?php echo '?goal_id='.$row['goal_id']; ?>">Edit</a></td>
    <?php

    ?>
    </tr>
    </table>
    Also I am not sure if this has anything to do with my login page's code:
    PHP Code:
    <?php
    session_start
    ();
    $con=mysqli_connect("localhost","","","") or die();
     if(isset(
    $_POST['submit']))
     {
      
    $username trim($_POST['username']);
      
    $password trim($_POST['password']);
      
    $permission trim($_POST['permission']);

    $query ="SELECT * FROM useraccount WHERE username='$_POST[username]'and password='$_POST[password]' and permission='$_POST[permission]'";
     
    $resultmysqli_query($con,$query) or die(mysqli_error());
    //$num_row = mysqli_num_rows($result);
    while($row mysqli_fetch_array($result)){
        if(
    $_SESSION['account_id']=$row['username'] && $_POST['password']=="$password&& $_POST['permission']=="Student")
        {
            
            
    header("Location:studentAccount.php");
                    exit;
        }
           else if(
    $_SESSION['account_id']=$row['username']&& $_POST['password']=="$password&& $_POST['permission']=="Staff")
        {
            
            
    header("Location:staffAccount.php");
                    exit;
        }
        else 
        {
            echo 
    "You got credentials wrong"
        }
    }
     }
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    663
    I do believe that if you learned how to turn on error checking you would find a host of error messages to help you clean up your current problems. Try it - you'll like it.

    PHP Code:
        error_reporting(E_ALL E_STRICT E_NOTICE);
        
    ini_set('display_errors''1');  // turn this off when development is done
        
    ini_set('log_errors','1'); 
    You say that you are a beginner. Looking at this code you are obviously copying it from somewhere. How will you learn if you don't WRITE your own code?

  3. #3
    Join Date
    Mar 2014
    Posts
    2
    sorry but from your code
    you have session of $_SESSION['account_id'] that seems an ID number

    but into the query you search buy username

    are you sure that are the same field?

    Bye

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles