View Full Version : Determining if link was pressed

06-16-2010, 07:20 PM
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.

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




<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(){
if(time == 0){
document.getElementById("countdown").innerHTML = "<a href='surf.php'>Next</a>";
document.getElementById("countdown").innerHTML = time;
var t = setTimeout("countdown()", 1000);
<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>
<!-- Exp -->
<div id="exp" align="center">
<!-- Timer -->
<div id="timer" align="center">
<div id="countdown">2</div>
Total Surfed: 78<br />
Credits Earned: 78<br />
<!-- Bonus -->
<div id="bonus" align="center">
<p><strong>Surf 25 More for <br>a 25 Credit Bonus!</strong></p>
<!-- Banner -->
<div id="banner" align="center">
<img src="img/ptc.jpg" alt="ptc">



// surf.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"];
echo 'error';
<title>My Traffic Exchange</title>
top.surfbar.location = 'surfbar.php'
top.Site.location = '<?php echo $url; ?>';
<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" />
<body><p>Sorry, but your Browser does not support Frames. Please open this page in a new browser.</p></body>

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:

$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'");

06-17-2010, 03:03 AM
If you make the next button a submit button then check if it has been initiated:

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.

06-17-2010, 03:09 AM
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.

06-17-2010, 03:15 AM
A submit button can be 100% customisable :)

Just attach a css style to it:

<input type="submit" class="button" name="next" value="Next" />

.button {
color: #000;
border: none;
background-color: #FFF;

Play with your hearts content

06-17-2010, 03:17 AM
Will give that a try then. Thanks very much!