title: How to view persons profile when their name is clicked in the table? php database
body: <p>Basically I am building this site/portal where a user is able to log in, fill out some information and store it (stores in the database). There is also admins. When admin logs in it opens up an admin page which has a table of all registered users on the site. What I need to to is when an admin presses on the name from the table (or button that says "view profile") it stores the email of the user in $_SESSION['email'] and id of the user in $_SESSION['user_id'] after which it redirects him to the profile overview page where it (using the email and user id) pulls up all the information from database about the user.</p>
  
  <p>Now the problem... Currently I can't wrap my mind around how it would know which data to save in the new variables, and how it would save it exactly since it's only printing out data (as far as I know) while it builds the table, after which I don't think theres a way to isolate rows and basically say that "if this user was clicked, pick the email that was on the same row, as well as his id".</p>
  
  <p>Here is my php. (first part is at the very top of the page. And the second part is the php thats inside the html body</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
    // The user is redirected here from login.php.
    session_start();// Start the session.
    // If no session value is present, redirect the user:
    if (!isset($_SESSION['id'])) {
      exit;
    }
  
      // Print a customized message
      echo "&lt;img src=\"skcac_logo.png\" alt=\"SKCAC Logo\" width=\"300px\"&gt;";
      //&lt;p align='right'&gt;&lt;a href=\"logout.php\"&gt;Logout&lt;/a&gt;&lt;/p&gt;";
  
      //connect to database
      require ('mysqli_connect.php');
      //make the query
      $q = "SELECT id, CONCAT(lastName, ', ', firstName) AS name, email FROM 
      Client ORDER BY lastName ASC";
      $r = @mysqli_query($dbc, $q);
  
      //count the number of returned rows
      $num = mysqli_num_rows($r);
  </code></pre>
  
  <p>second part</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
        if ($num &gt; 0)
        {
            //print how many users there are
            echo "&lt;p&gt; There are currently $num registered participants.&lt;/p&gt;";
  
            //table header
            echo '&lt;div class="col col-2"&gt;&lt;/div&gt;
                  &lt;div class="col col-8 table_div"&gt;&lt;table class="table"&gt;
                  &lt;thread&gt;
                  &lt;tr&gt;
                    &lt;th scope="col" align="center"&gt;ID&lt;/th&gt;
                    &lt;th scope="col" align="center"&gt;Name&lt;/th&gt;
                    &lt;th scope="col" align="center"&gt;Email&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;/thread&gt;
            &lt;tbody&gt;';
  
            //Fetch and print all the records:
            while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
            {
                echo
                    '&lt;tr&gt;
                      &lt;td align="center"&gt;' . $row['id'] . '&lt;/td&gt;
                      &lt;td align="center"&gt;&lt;a class="client_name" href="client_profile_overview.php"&gt;' . $row['name'] . '&lt;/a&gt;&lt;/td&gt;
                      &lt;td align="center"&gt;' . $row['email'] . '&lt;/td&gt;
                      &lt;td align="center"&gt;&lt;button type="button" class="btn btn-default btn-sm view_profile_btn" id="view_profile_btn"&gt;View Profile&lt;/button&gt;&lt;/td&gt;
                    &lt;/tr&gt;';
                if (isset($_POST['view_profile_btn']))
                {
                    $_SESSION['participants_id'] = $row['id'];
                    $_SESSION['participants_name'] = $row['name'];
  
                    redirect_user('client_profile_overview.php');
                }
            }
            //close the table and free up the resources.
            echo '&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
             &lt;div class="col col-2"&gt;&lt;/div&gt;';
            mysqli_free_result($r);
        }
        else //if no records were returned
        {
            //Public message
            echo '&lt;p class="error"&gt;There are currently no registered users.&lt;/p&gt;';
  
            //debuggin message
            echo '&lt;p&gt;' . mysqli_error($dbc) . '&lt;br&gt;&lt;br&gt;Query: ' . $q . '&lt;/p&gt;';
        }//end of if ($r) IF
        ?&gt;'
  </code></pre>