Jump to content

help with if statement


MDanz

Recommended Posts

its not working.. it just echos "success!" even when i just posted a second ago.  The only time i should see "success" is after 50 seconds.. Where did i go wrong?

 

$username = $_SESSION['username'];
  mysql_connect("localhost", "Master", "password");
mysql_select_db("dbk");
$result = mysql_fetch_assoc(mysql_query("SELECT * FROM Stacks"))or die (mysql_error());
$user = $result['username'];
$time = $result['posted'];

if ( ($time > (time()-50)) && ($username == $user) )

    {
  echo "<font color=white>You must wait 30 seconds between submits</font>";
}

else {
echo "Success!";
}

Add this debugging line to your code just before your IF statement

 

echo "The value of my variable $time is : ".$time." The value of time() is : ".time()." The difference between the two is : ".$time-time();

 

Let me know what you get.

 

i tried that and i get this -1253024435 it doesn't even say the words  just -1253024435

 

 

still not working..  :confused:

<?php
session_start();
include("connect.php");
$username = $_SESSION['username'];
  mysql_connect("localhost", "ustackc1_Master", "KOWstHbK");
mysql_select_db("ustackc1_Ustack");
$result = mysql_fetch_assoc(mysql_query("SELECT * FROM Stacks WHERE username='$username'"))or die (mysql_error());
$user = $result['username'];
$time = $result['posted'];




if ((time() - $time < 50))

    {
  echo "<font color=white>You must wait 30 seconds between submits</font>";
}

else

{
echo "success";
}

Here is a troubleshooting hint: when a comparison fails, echo out the value(s) being used in the comparison so that you know exactly what it is.

 

Are you even sure that there is a row in Stacks for the username? Your code is not checking if the query worked or failed and that there is a row in the result set.

 

What do you get when you add the following two lines of code immediately after your first opening <?php tag -

 

ini_set("display_errors", "1");
error_reporting(E_ALL);

still get the same page

 

the query is working, there is a row in Stacks for that username..  each row has a timestamp

 

when i do this

 

echo "The value of my variable $time is : ".$time." The value of time() is : ".time()." The difference between the two is : ".$time-time();

 

it displays

"-1253026593"

 

it doesn't even show the text in the echo just "-1253026593"

 

when i echo $time i get this  2009-08-31 23:41:52

 

 

they are in two different formats?

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.