Get Info When Link Is Clicked

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Get Info When Link Is Clicked

Post by Smudly »

I am attempting to write a script that will add 100 points to a user's account once they click on a link. I'm using some javascript that has the link, and some php that will $_GET the URL information that was passed in, then update the user's points.

Here's the code I've got, but I've yet to get it to work successfully.

Code: Select all

<?php
session_start();

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

$viewedquery = mysql_query("SELECT `todaysurfed`, `exp`, `level` FROM `userstats` WHERE id='$userid'");
$row = mysql_fetch_assoc($viewedquery);

$todaysurfed = $row['todaysurfed'];

if (isset($_GET['next'])){
include('exp.php');
$siteview ++  ;

$viewedsites = "UPDATE userstats SET exp='$newexp', level='$newlevel', todaysurfed='$siteview' WHERE id='$userid'";
mysql_query($viewedsites);
}

<html>
<head>
<title>My Site</title>
<script>
top.surfbar.location = 'surfbar.php'
top.Site.location = '<?php echo $url; ?>';
</script>
<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="surfbar.php?next=<?php echo urlencode($siteview);?>">Next</a>';
    }else{
        document.getElementById("countdown").innerHTML = time;
        var t = setTimeout("countdown()", 1000);
    }
}
</script>
</head>
<body onload="startCountdown();">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<?php
echo "<tr><td style=\"background:#333333;height:80px;border-bottom:#aaaaaa solid 2px;\">";
include('surfbar.php');
echo "</td></tr>";
?>
<tr><td>
<iframe src="<?php echo $url;?>" width="100%" height="100%" frameborder="0" name="Site" marginwidth="O" marginheight="0" noresize scrolling="auto">
  <p>Your browser does not support iframes.</p>
</iframe>
</td></tr>
</table>
</body>
</html>
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Get Info When Link Is Clicked

Post by andyhoneycutt »

Not sure if you're intending to, or not, but you're not grabbing the data from your first query and storing it anywhere or doing much anything with it. You then update the user's row with variables created out of thin air.

When you say that you've not got it running right yet, what problems are you encountering?
Post Reply