Jump to content

Determining if link was pressed


Smudly

Recommended Posts

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

<?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

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:

 


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

Link to comment
Share on other sites

I've done it like this in the past, using sessions, but there are alot of different ways.

 

// In this case, $count is a remaining number out of a total number ex. 3 out of 10 so count would be 7 and Next button would be displayed
if ($count > 0) {
// then set a session var to match
$_SESSION['submit'] = "next";
echo '<div><button type="submit" name="next">Next</button>';	
} else {
        $_SESSION['submit'] = "done";
echo '<div><button type="submit" name="done">Done</button>';
echo "Thank you for completing survey!<br />Hit <i>Done</i> when finished!";
}

// Then you can check 
if ($_SESSION[submit] == "next") {
do something
} else {
do something else
}

 

Not exact, and not tested, but should get you going in the right direction. Hope that helps

Link to comment
Share on other sites

You may use javascript without the use of ajax as below, hope this will

      work fine. If not please look into the jquery library and using ajax with it, for more help.

   

<script>

function addpoint(userid,point){

  document.form1.userid=userid;

  document.form1.point=point;

  document.form1.submit();

}                                 

</script>

 

<a href="javascript:void(0);" onclick="addpoint(445656888,100)">Add 100 Point</a>

<a href="javascript:void(0);" onclick="addpoint(878655644,100)">Add 100 Point</a>

 

<form method="post" action="thispage.php" name="form1">

<input type="hidden" name="point" value="">

<input type="hidden" name="userid" value="">

</form>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.