Results 1 to 7 of 7

Thread: submission counter

  1. #1
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking submission counter

    i have updated this script hoping i am on the right trail any thoughts?

    hey all, i wrote a submission counter this mornign and was wondering if one of you php gurus could proof read it for me and tell em if i am on the right track.

    what it is suppose to do is, track how many times users submit a form on my website, and if they have already done it than it will not track them more than once. but it tracks how many people have submitted through the function and a session id, and if it reaches x amount than it will produce a error when they submit saying sorry contest is over. i am very thankfull for all the help. i am still working on this but figured i would toss it out for review by some of you pro's.
    so here is the php and sql
    PHP Code:
    <?php
    $dbhost 
    'localhost';    
    dbuser 'session';            
    $dbpass '123456';        
    $dbname 'session';    
    ?>
    <?php
    /////////////////////Connect to Database///////////////
    function dbconnect () {
        global 
    $dbhost$dbuser$dbpass$dbname;
        global 
    $MYSQL_ERRNO$MYSQL_ERROR;
        
        
    $link_id mysql_pconnect ($dbhost$dbuser$dbpass);
        if(!
    $link_id) { 
            
    $MYSQL_ERRNO 0;
            
    $MYSQL_ERROR "Could not connect to the host $dbhost.";
            return 
    0;
        } else if (empty(
    $dbname) && !mysql_select_db($dbname)) {
            
    $MYSQL_ERRNO mysql_errno();
            
    $MYSQL_ERROR mysql_error();
            return 
    0;
        } else {
            return 
    $link_id;
        }
    }
    ?>
    <?php
    dbconnect
    ();
    session_start();
    ?>
    <?php
    /////////////////////////Submission Counter///////////////////////
    function submissionCounter(){
    $check mysql_query(ppl_submitted);
    if(!
    session_is_registered('submitted')){
        
    $check("INSERT INTO ppl_submitted (session_id, ip_address, user_agent) <br>        VALUES ('".session_id()."', '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_USER_AGENT']}')");
        
    session_register('submitted');
    } else {
        if(
    session_is_registered('user_id')){
            
    $check("UPDATE ppl_submitted, total_visit SET member='1' WHERE session_id='".session_id()."'");
        }
    }
    if(
    session_is_registered('submitted')){        
        
    $check("UPDATE ppl_submitted WHERE session_id='".session_id()."'");

    if(
    session_is_registered('complete')){
        
    $check("SELECT function(SUM(total_visit)) FROM ppl_submitted")
    }
    }
    ?>
    <?php
    //this would go on the submit form
    if (isset($_POST["Submit"]))
    {
        
    submissionCounter();
        
        for (
    $i 0$i 0$i++)
        {
            if (!empty(
    $check[$i]))
            {
                echo 
    "contest is over";
            }
        }
    }
    ?>
    <html>
    <head>
    </head>
    <body>
    <form action="" method="post">
    <input name="test" type="text" maxlength="5" value="" size="5" >
    <input name="test2" type="text" maxlength="3" value="" size="4" >
    <input type="submit" value="Submit" >
    </form>
    </body>
    </html>
    <!--sqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsql--
    CREATE TABLE ppl_submitted (
      session_id varchar(255) NOT NULL default '',
      total_visit varchar(150) NOT NULL default '0',
      member enum('1','0') default '0',
      ip_address varchar(255) NOT NULL default '',
      user_agent varchar(255) default NULL,
      PRIMARY KEY  (session_id),
      KEY session_id (session_id)
    ) TYPE=MyISAM;
    -------------------------------------------->
    feel free to tell me where i am wrong and help out in any way
    Last edited by pkcidstudio; 07-28-2006 at 07:21 PM.

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    just glancing at it ppl_submitted should be $ppl_submitted

  3. #3
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Quote Originally Posted by blm126
    just glancing at it ppl_submitted should be $ppl_submitted
    why do you say that when i put the "$" on it gives a blank screen

  4. #4
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    $check = mysql_query(ppl_submitted);
    inside of mysql_query() should be an SQL query i couldn't find something like:
    Code:
    $ppl_submitted = "SELECT * FROM tablename";
    $check = mysql_query($ppl_submitted);
    in ur given php code
    Last edited by jr_yeo; 07-28-2006 at 08:32 PM. Reason: typo error
    Please don't mind me. I am just posting a lot of nonsense.

  5. #5
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    cool keep it coming guys ill post current code i changed pp_submitted to submissionCounter you will see. i did this because i built the sql table around this name not thinking.
    here is code
    PHP Code:
    <?php
    /////////////////////Connect to Database///////////////
    $link mysql_connect('localhost''session''123456');
    if (!
    $link) {
       die(
    'Could not connect: ' mysql_error());
    }
    echo 
    'Connected successfully';
    mysql_close($link);
    ?> 
    <?php

    session_start
    ();
    ?>
    <?php
    /////////////////////////Submission Counter///////////////////////
    function submissionCounter(){

    $check mysql_query($submissionCounter);
    $submissionCounter "SELECT * FROM tablename";

    if(!
    session_is_registered('submitted')){
        
    $check("INSERT INTO submissionCounter (session_id, ip_address, user_agent) <br>        VALUES ('".session_id()."', '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_USER_AGENT']}')");
        
    session_register('submitted');
    } else {
        if(
    session_is_registered('user_id')){
            
    $check("UPDATE submissionCounter, total_visit SET member='1' WHERE session_id='".session_id()."'");
        }
    }
    if(
    session_is_registered('submitted')){        
        
    $check("UPDATE submissionCounter WHERE session_id='".session_id()."'");

    if(
    session_is_registered('complete')){
        
    $check("SELECT function(SUM(total_visit)) FROM submissionCounter");
    }
    }
    ?>
    <?php
    //this would go on the submit form
    if (isset($_POST["Submit"]))
    {
        
    submissionCounter();
        
        for (
    $i 0$i 1$i++)
        {
            if (!empty(
    $check[$i]))
            {
                echo 
    "contest is over";
            }
        }
    }
    ?>
    <html>
    <head></head>
    <body>
    <form action="" method="post">
      <input name="test" type="text" maxlength="5" value="" size="5" >
      <input name="test2" type="text" maxlength="3" value="" size="4" >
      <input type="submit" value="Submit" >
    </form>
    </body>
    </html>
    <!--sqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsql--
    CREATE TABLE submissionCounter (
      session_id varchar(255) NOT NULL default '',
      total_visit varchar(150) NOT NULL default '0',
      member enum('1','0') default '0',
      ip_address varchar(255) NOT NULL default '',
      user_agent varchar(255) default NULL,
      PRIMARY KEY  (session_id),
      KEY session_id (session_id)
    ) TYPE=MyISAM;
    -------------------------------------------->
    thank you agian for the help

  6. #6
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i think the
    Code:
    $submissionCounter = "SELECT * FROM tablename";
    should be b4 the
    Code:
    $check = mysql_query($submissionCounter);
    ?

    $submissionCounter should be initialized first b4 querying it
    Please don't mind me. I am just posting a lot of nonsense.

  7. #7
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    cool how does this section look?
    i want it to display the alert when i reach x amount
    PHP Code:
    <?php
    //this would go on the submit form
    if (isset($_POST["Submit"]))
    {
        
    submissionCounter();
        
    $xamount "1";
        for (
    $i 0$i $xamount$i++)
        {
            if (!empty(
    $check[$i]))
            {
                echo 
    "contest is over";
            }
        }
    }
    ?>
    Last edited by pkcidstudio; 07-28-2006 at 08:50 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •