PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,391 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,571 people online right now. Registration is fast and FREE... Join Now!




A problem that involves requiring another page

 

A problem that involves requiring another page, still shows the data even if it's not ment to be shown

Decypher

2 Jul, 2009 - 11:40 AM
Post #1

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
ok after solving the mktime problem, I used that code to make a new page called jailtimer, This will go on every page where if the user is in jail they aren't allowed to use that feature.

so on the certain pages in the correct position I use the require tool to bring the jailtimer to check if the user is in jail or not. Eventhough this is successful and if they are in jail it shows how long left they have in jail it still shows the data below it...

crimes.php
CODE

<?php
   require("jailtimer.php");
   echo '<br>';
if (isset($_SESSION['userid'])) {
    // this is because i dont like MySQL timestamp i like the UNIX style
    function revertcrimetime($str) {
        list($date, $time) = explode(' ', $str);
        list($year, $month, $day) = explode('-', $date);
        list($hour, $minute, $second) = explode(':', $time);

        $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
        return $timestamp;
    }

    $q = "SELECT crimetimer FROM login WHERE id='".$_SESSION["userid"]."'";
    $r = mysql_query($q);
    $v = mysql_fetch_array($r);
    $lastActive = revertcrimetime($v['crimetimer']);

    if (($lastActive + (1.5*60) - time() > 0)) { // 10*60 = 10 minutes change 10 to 5 if you want 5 min
        // session expired send to index
        $result = $lastActive + (1.5*60) - time();
        echo 'You cannot commit a crime for '.$result.' seconds.';
        
        
    }else {?>
        
<form method = "post"
      action = "crime.php">

<table border="1" cellspacing="0" bordercolor="#000000"width= "200">
<tr><td colspan="2" bgcolor="#666666" align="center"><b>Crimes</b></td></tr>

<?php
$query ="SELECT id, crime FROM crimes ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result))
{
    $id = $row['id'];
    $crime = $row['crime'];
    echo'
<tr><td width="10">
<input type = "radio"
name = "crimeid"
value = "'.$id.'"></td><td align="right">'.$crime.'</tr>';}?></table>

   <center>
   <br>
  
   <input type = "submit"
          value= "Commit">
          
          
   </center>
</form>
<? } }
?>  


jailtimer.php
[code]
<?
$query = "SELECT username FROM login WHERE id='".$_SESSION["userid"]."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$username = $row['username'];

$qu = "SELECT * FROM jail WHERE username = '".$username."'";
$re = mysql_query($qu);
$vu = mysql_fetch_array($re);

if ($vu != 0){
function revertjailtime($str) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}


$q = "SELECT time, length FROM jail WHERE username='".$username."'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);
$length = $v['length'];
$lastActive = revertjailtime($v['time']);
if ($lastActive + $length - time() > 0) {
$result = $lastActive + $length - time();
echo 'You are still in jail for '.$result.' seconds.';

} else {
$delete="DELETE FROM jail WHERE username = '".$username."'";
mysql_query($delete);
}}
?>[code]


User is offlineProfile CardPM
+Quote Post


TTechGuy

RE: A Problem That Involves Requiring Another Page

2 Jul, 2009 - 02:58 PM
Post #2

D.I.C Head
**

Joined: 24 Apr, 2009
Posts: 57



Thanked: 3 times
My Contributions
There is nothing to stop the execution of code if they are still in jail. You would need an if then in your page saying if $result > 0 then do something other than show this info.
User is offlineProfile CardPM
+Quote Post

Decypher

RE: A Problem That Involves Requiring Another Page

3 Jul, 2009 - 03:58 AM
Post #3

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
ah, okay cheers
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: A Problem That Involves Requiring Another Page

3 Jul, 2009 - 09:11 PM
Post #4

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
for checking number of rows you can use mysql_num_rows($query).

change your this code
php
if ($vu != 0){

to
php

$num = mysql_num_rows($re);
if ($num != 0){


This post has been edited by noorahmad: 3 Jul, 2009 - 09:11 PM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:46PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month