Topic: A nice little app in progress

<?php

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'header.php';
include PUN_ROOT.'tlhead.php';



//Make sure they use the form to access this page
if (isset($_POST['submit'])) 
{
    //Insert a new attempt MySQL is set to make sure only one new attempt is put in per day / per user
    $query = "INSERT INTO pun_contest (username, last_try) VALUES ('" . $pun_user['username'] . "', NOW())"; 
    $result = $db->query($query); 
    
    //If  they are allowed to enter a new attempt at this time 
    if ($result != $db->error) 
    { 
    echo "Your attempt has been added to the total."; 
    }
    //If they are not allowed to enter a new attempt at this time
    if ($result == $db->error) 
    {
    echo "You may only make one new attempt per day.";
    }
    //If they are the correct number to have tried, they win
    if ($db->num_rows($result) == 1)
    {
    echo 'Congratulations, you are the first.';
    }
}
else
{
echo "New challenges must be sent from the correct page.";
}
    
require PUN_ROOT.'footer.php';

Re: A nice little app in progress

without the tlhead.php please lol

FluxBB - v1.4.8

3

Re: A nice little app in progress

First of all, and really sorry to say, but this is unlikely to work.
You want first to find out if a user is allowed to participate.
So you need a SELECT statement.
Your INSERT statement will just insert, returning either sucess or failure.
The insert statement does not check for duplicates unless you use a primary key made of the userid AND the date.
And next, on success it will always return 1, so your script will tell [everybody to be the first.. smile

Last, the check for the "submit" value is not a useful means to find out if somebody comes from a certain page.
You need to work with $_SERVER['HTTP_REFERER'] there, which again has issues with certain firewalls.

The German PunBB Site:
PunBB-forum.de

4 (edited by towelie 2007-06-11 18:44)

Re: A nice little app in progress

I totally changed everything about the script wink Ill update here when I have time.
Oh and I am using those 2 as primary already.