Jump to content
MakeWebGames

$_POST help


Recommended Posts

Since I am using a $_POST method to find the userid, when I head onto the next page I get the error: Invalid user, Please go back and try again.

I need something which will make the $_POST carry onto the next page as this is my problem I believe.

 

function select_user_logs()
{
   global $db, $ir, $sa;                 
   echo "Select the user which you want to view their log.
   <form action='staff_userlogs.php?action=viewlogs' method='post'>
           User: " . userlogged_dropdown(NULL, 'user')
               . "
           <br />
           <input type='submit' value='Submit' />
       </form>"; 
}
function view_user_logs()
{
   global $db, $ir, $sa;

  if (!isset($_GET['st']))
   {
       $_GET['st'] = 0;
   }
   $st = abs(intval($_GET['st']));
   $app = 100;

       $_POST['user'] =
           (isset($_POST['user']) && is_numeric($_POST['user']))
                   ? abs(intval($_POST['user'])) : 0;

   if (empty($_POST['user'])) {
       error('Invalid user.');
   }
   $query = $db->query("SELECT COUNT(`uUSERID`)
                    FROM `user_logs`
                                WHERE `uUSERID` = {$_POST['user']}");
   $logs = $db->fetch_single($query);
   $db->free_result($query);
   if ($logs == 0)
   {
       error('There have been no logs yet from this user.');
   }
   $pages = ceil($logs / $app);

   $q = 
       $db->query("
           SELECT `userid` FROM `users` WHERE `userid` = {$_POST['user']}");
   if ($db->num_rows($q) == 0) {
       $db->free_result($q);
       error('User doesn\'t seem to exist, Please go back and try again.');
   }
   echo "<hr width = '75%'><table width = '75%' cellpadding = '1' cellspacing = '1' class = 'table'>
       <tr>
           <th>User</th>
           <th>Address</th>
           <th>Time</th>
       </tr>";
   $query = $db->query("SELECT `uID`, `uUSERID`, `uADDRESS`, `uTIME` 
                            FROM `user_logs`
                            WHERE `uUSERID` = {$_POST['user']}
                            ORDER BY `uTIME` DESC
                            LIMIT $st, $app");

       while ($r = $db->fetch_row($query)) {
           echo "<tr>
           <td>" . $sa->username_nonformat($r['uUSERID'], TRUE) . "</td>
           <td>{$r['uADDRESS']}</td>
           <td>" . date("F j, Y, g:i:s a", $r['uTIME']) . "</td>
           </tr>";
}  
   echo"</table><hr width = '75%'>
   Pages: 
      ";
   for ($i = 1; $i <= $pages; $i++)
   {
       $s = ($i - 1) * $app;
       echo ($s == $st) ? '<b>' . $i . '</b> '
               : '<a href="staff_userlogs.php?action=viewlogs&st=' . $s . '">'
                       . $i . '</a> ';
       echo ($i % 25 == 0) ? '<br />' : '';
   }
   $mypage = floor($_GET['st'] / 100) + 1;
   stafflog_add("Viewed " . $sa->username_nonformat($_POST['user'], TRUE) . " user logs. (Page: $mypage)");
}
Link to comment
Share on other sites

Untested..

function view_user_logs() {
   global $db, $ir, $sa;
   $_GET['user'] = array_key_exists('user', $_GET) && ctype_digit($_GET['user']) ? $_GET['user'] : null;
   ?>Select the user which you want to view their log.
   <form action="staff_userlogs.php?action=viewlogs" method="get">
       User: <?php echo userlogged_dropdown(NULL, 'user', $_GET['user']);?><br />
       <input type="submit" value="Submit" />
   </form><?php
   if(!empty($_GET['user'])) {
       $st = array_key_exists('st', $_GET) && ctype_digit($_GET['st']) ? $_GET['st'] : 0;
       $app = 100;
       if(empty($_GET['user']))
           error('Invalid user.');
       $query = $db->query('SELECT COUNT(`uUSERID`) FROM `user_logs` WHERE `uUSERID` = '.$_GET['user']);
       $logs = $db->fetch_single($query);
       $db->free_result($query);
       if ($logs == 0)
           error('There have been no logs yet from this user.');
       $pages = ceil($logs / $app);
       $q = $db->query('SELECT `userid` FROM `users` WHERE `userid` = '.$_GET['user']);
       if ($db->num_rows($q) == 0) {
           $db->free_result($q);
           error('User doesn\'t seem to exist, Please go back and try again.');
       }
       $query = $db->query('SELECT `uID`, `uUSERID`, `uADDRESS`, `uTIME` FROM `user_logs` WHERE `uUSERID` = '.$_GET['user'].' ORDER BY `uTIME` DESC LIMIT '.$st.', '.$app);
       ?><hr width="75%"><table width="75%" cellpadding="1" cellspacing="1" class="table">
           <tr>
               <th>User</th>
               <th>Address</th>
               <th>Time</th>
           </tr><?php
       if(!$db->num_rows($query))
           echo '<tr><td colspan="3" class="center">There are no logs available</td></tr>';
       else
           while($r = $db->fetch_row($query)) {
               ?><tr>
                   <td><?php echo $sa->username_nonformat($r['uUSERID'], true);?></td>
                   <td><?php echo $r['uADDRESS'];?></td>
                   <td><?php echo date("F j, Y, g:i:s a", $r['uTIME']);?></td>
               </tr><?php
           }
       ?></table><hr width="75%">
       Pages: <?php
       for($i = 1; $i <= $pages; ++$i) {
           $s = ($i - 1) * $app;
           echo ($s == $st) ? '<b>' . $i . '</b> ' : '<a href="staff_userlogs.php?action=viewlogs&st=' . $s . '&user='.$_GET['user'].'">' . $i . '</a> ';
           echo ($i % 25 == 0) ? '<br />' : '';
       }
       $mypage = floor($_GET['st'] / 100) + 1;
       stafflog_add('Viewed ' . $sa->username_nonformat($_GET['user'], true) . ' user logs. (Page: '.$mypage.')');
   }
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...