Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Determining if link was pressed
Old 06-16-2010, 01:20 PM Determining if link was pressed
Skilled Talker

Posts: 83
Trades: 0
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'"); 
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-16-2010, 01:24 PM Re: Determining if link was pressed
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
pass a parameter with the link.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-16-2010, 01:44 PM Re: Determining if link was pressed
Skilled Talker

Posts: 83
Trades: 0
I'm not too sure how to parse it correctly.

This is what I tried, but didn't work:
PHP Code:
<?php
session_start
();

$newexp $_GET['exp'];
$plusexp $newexp 100;
$userid $_SESSION['userid'];

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

while(
$row mysql_fetch_assoc($expquery))
{
    
$exp $row['exp'];
    
}
if (isset(
$next)){
include(
'inc/connect.php');

$inputexp mysql_query("UPDATE users SET exp='$plusexp' WHERE id='$userid'");
}
?>

<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?surf&exp=<?php echo urlencode($plusexp);?>' name='surf'>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>
Not getting any errors, just isn't parsing.
Smudly is offline
Reply With Quote
View Public Profile
 
Old 06-16-2010, 02:07 PM Re: Determining if link was pressed
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It looks like the link is malformed.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-18-2010, 07:17 PM Get Info When Link Is Clicked
Skilled Talker

Posts: 83
Trades: 0
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.

PHP Code:
<?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>
Smudly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Determining if link was pressed
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21986 seconds with 12 queries