Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Determining if link was pressed

    Hi, I am trying to store a variable into my database upon a user's click.

    Once a user clicks on the link, a value of 100 should be added to their score.
    The page includes 2 frames. The top has the button "Next" (once it's clicked, the points are added).
    The bottom, shows a random website from a list in my database.
    How could write a script that could do something like this?

    The script uses the users table. This has information like the user's id which will be used to determine which user is gaining the points, and exp, which is where the points should be added.
    Code:
    Database Version: 5.0.91
    Table information:
    Name: users
    id      int(11)       No                
    username     varchar(25)     No             
    level     int(2)     No      1       
    email     varchar(64)     No             
    fname     varchar(25)     No             
    lname     varchar(25)     No             
    member     tinyint(1)     No             
    referrer     varchar(25)     No             
    joindate     date     No             
    lastsurfed     date     No             
    credits     decimal(9,3)     No             
    exp     int(6)     No             
    password     varchar(32)     No             
    ip     varchar(15)     No
    Here is my current code. This is surfbar.php
    Code:
    <?php
    
    session_start();
    
    ?>
    
    <html>
    <head>
    <title>My Traffic Exchange</title>
    <link rel="stylesheet" type="text/css" href="styles/surfbar.css" />
    <script type="text/javascript">
    
    var time = 2;
    
    function startCountdown(){
        var t = setTimeout("countdown()", 1000);
    }
    
    function countdown(){
        --time;
        if(time == 0){
            document.getElementById("countdown").innerHTML = "<a href='surf.php'>Next</a>";
        }else{
            document.getElementById("countdown").innerHTML = time;
            var t = setTimeout("countdown()", 1000);
        }
    }
    </script>
    </head>
    <body onload="startCountdown();" class="surfbar" bgcolor="#333333">
    
    <!-- Surfing Container -->
    
    <div id="container">
    
    <!-- Logo -->
    <div id="logo" align="center">
    	<img src="img/ad.jpg" alt="ptc" width="150" height="48"><br />
        <a href="member.php">Members Area</a>
    </div>
    <!-- Exp -->
    <div id="exp" align="center">
    	<p><strong>Experience:</strong><p>
    </div>
    <!-- Timer -->
    <div id="timer" align="center">
    	<div id="countdown">2</div>
    	<p><strong>
        Total Surfed: 78<br />
        Credits Earned: 78<br />
        </strong></p>
    </div>
    <!-- Bonus -->
    <div id="bonus" align="center">
    	<p><strong>Surf 25 More for <br>a 25 Credit Bonus!</strong></p>
    </div>
    <!-- Banner -->
    <div id="banner" align="center">
    	<img src="img/ptc.jpg" alt="ptc">
    </div>
    
    </div>
    
    </body>
    </html>
    // surf.php
    PHP Code:
    <?php

    session_start
    ();
    include(
    'inc/connect.php');
    $userid $_SESSION['userid'];

    // Select a Random Website
    $sitequery "SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active
    FROM users JOIN websites ON websites.userid = users.id
    WHERE websites.active='yes' and users.credits > 0 order by rand() LIMIT 1"
    ;

    $siteresult mysql_query($sitequery) or die("Error in query: $sitequery. " mysql_error());

    if (
    mysql_num_rows($siteresult) != 0){
        
    $siterow mysql_fetch_array($siteresult);
        
    $url $siterow["url"];
    }
    else{
         echo 
    'error';
    }
    ?>
    <html>
    <head>
    <title>My Traffic Exchange</title>
    <script>
    top.surfbar.location = 'surfbar.php'
    top.Site.location = '<?php echo $url?>';
    </script>
    </head>
    <frameset rows="80,*" BORDERCOLOR="#222222" BORDER="3">
              <frame src="surfbar.php" name="surfbar" marginwidth="O" marginheight="0" NORESIZE SCROLLING="no" />
              <frame src="<?php echo $url ?>" name="Site" marginwidth="O" marginheight="0" noresize scrolling="auto" />
    </frameset>
    <noframes>
    <body><p>Sorry, but your Browser does not support Frames. Please open this page in a new browser.</p></body>
    </noframes>
    </html>
    I just need help determining how to determine if Next was clicked, and if it was, add 100 to the exp in the database.

    Here is some basic pseudocode of how I think it could work:

    PHP Code:

    include('inc/connect.php');
    $userid $_SESSION['userid'];

    $expquery mysql_query("SELECT `exp`, `level` FROM users WHERE id=$userid");
    $row mysql_num_rows($expquery);

    while(
    $row mysql_fetch_assoc($expquery))
    {
        
    $exp $row['exp'];
    }
    if (
    surfed){
    $newexp += 100;
    }
    $inputexp mysql_query("UPDATE users SET exp='$newexp' WHERE id='$userid'"); 

  • #2
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    If you make the next button a submit button then check if it has been initiated:
    PHP Code:
    <?php
    if (isset($_POST['buttonname'])) {
       
    $points $oldpoints $newpoints
       $mysql 
    mysql_query("UPDATE ....");
    }
    ?>
    Then if you wanted to have the user linked to another page, just have a header refresh redirect the user to the url.

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I like that idea, but only problem is I need it to be stylized to look just like a typical hyperlink.

    From what I've seen, you can change the color, and font, but are stuck with the rectangle background of the button.

  • #4
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    A submit button can be 100% customisable

    Just attach a css style to it:

    Code:
    <input type="submit" class="button" name="next" value="Next" />
    Code:
    .button {
       color: #000;
       border: none;
       background-color: #FFF;
    }
    Play with your hearts content

  • Users who have thanked Jazz914 for this post:

    Smudly (06-17-2010)

  • #5
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Will give that a try then. Thanks very much!


  •  

    Posting Permissions

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