
February 4th, 2005, 07:11 AM
|
|
Contributing User
|
|
Join Date: Jul 2004
Posts: 59
Time spent in forums: 2 h 57 sec
Reputation Power: 5
|
|
|
Link Referral System
Here is my problem:
I am creating a links system with a hits system (in and out). The links are created wonderfully, and the "out" url (?p=referout&id=whatever) is created appropriately. But the "In" url (?p=referin&id=whatever) is always wrong: "id" is always assigned to "1", so it only updates the "in" hits for the first link inserted into the database.
I am wondering how to make it assign the correct ID number for each "in" url (?p=referin&id=CORRECT#!!!!).
Here are the scripts for the following files:
add_link.php
links.php
referin.php
add_link.php
PHP Code:
<?
$continue = $_POST['continue'];
$confirm = $_POST['confirm'];
$edit = $_POST['edit'];
if($continue)
{
$refername = $_POST['refername'];
$linkurl = $_POST['linkurl'];
$buttonurl = $_POST['buttonurl'];
echo "<strong>Is the following correct?</strong><br><br>";
echo "Referer Name: <strong>" . $refername . "</strong><br>";
echo "Link URL: <strong>" . $linkurl . "</strong><br>";
echo "Button: <img src=\"" . $buttonurl . "\" border=\"0\" width=\"88\" height=\"31\" /><br>";
echo "<form method=\"post\" action='?p=add_link&confirm'>";
echo "<input type=\"hidden\" name=\"refername\" value=\"" . $refername . "\">";
echo "<input type=\"hidden\" name=\"linkurl\" value=\"" . $linkurl . "\">";
echo "<input type=\"hidden\" name=\"buttonurl\" value=\"" . $buttonurl . "\">";
echo "<input type=\"Submit\" name=\"edit\" value=\"<< Go back\"> ";
echo " <input type=\"Submit\" name=\"confirm\" value=\"Confirm >>\">";
echo "</form>";
}
elseif($edit)
{
$refername = $_POST['refername'];
$linkurl = $_POST['linkurl'];
$buttonurl = $_POST['buttonurl'];
echo "<form method=\"post\" action='?p=add_link&continue'>";
echo "<strong>Site Name:</strong> <input type=\"Text\" name=\"refername\" value=\"" . $refername . "\"><br>";
echo "<strong>Web Address:</strong> <input type=\"Text\" name=\"linkurl\" value=\"" . $linkurl . "\"><br>";
echo "<strong>Button Link:</strong> (optional)(88x31 only) <input type=\"Text\" name=\"buttonurl\" value=\"" . $buttonurl . "\"><br>";
echo "<input type=\"Submit\" name=\"continue\" value=\"Continue >>\">";
echo "</form>";
}
elseif ($confirm)
{
$refername = $_POST['refername'];
$linkurl = $_POST['linkurl'];
$buttonurl = $_POST['buttonurl'];
$sql = "INSERT INTO refer (site,url,img_url) VALUES ('" . addslashes( $refername ) . "','" . addslashes( $linkurl ) . "','" . addslashes( $buttonurl ) . "')";
$insert = mysql_query($sql);
if($insert) {
$result = mysql_query("SELECT * FROM `refer`");
echo mysql_error();
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
echo "Link added successfully!";
echo "<br><br>";
echo "<u>Please link to my site with the following URL:</u><br>";
echo "<strong><em>http://yaggles.b7p.info/?p=referin&id=" . $id . "</em></strong>";
}
else
{
die("Cannot query database!");
}
}
else
{
echo "<form method=\"post\" action='?p=add_link&confirm'>";
echo "<strong>Site Name:</strong> <input type=\"Text\" name=\"refername\"><br>";
echo "<strong>Web Address:</strong> (With http:// included!)<input type=\"Text\" name=\"linkurl\"><br>";
echo "<strong>Button Link:</strong> (optional)(88x31 only) <input type=\"Text\" name=\"buttonurl\"><br>";
echo "<input type=\"Submit\" name=\"continue\" value=\"Continue >>\">";
echo "</form>";
}
?>
links.php
PHP Code:
<?PHP
require_once("conf.php");
$_REQUEST['add'];
?>
<center><h1>Links</h1></center>
<BR /><BR />
<?PHP
if($add)
{
echo "<meta refresh='refresh' content='0;?p=add_link'>";
}
else
{
$result = mysql_query("SELECT * FROM refer ORDER BY refin DESC");
echo mysql_error();
while($myrow = mysql_fetch_array($result)) {
$linkurl = $myrow["url"];
$refername = $myrow["site"];
$buttonurl = $myrow["img_url"];
$referin = $myrow["refin"];
$referout = $myrow["refout"];
$id = $myrow["id"];
echo "<div align=\"center\"><a href=\"?p=referout&id=" . $id . "\"><img src=\"" . $buttonurl . "\"";
if($buttonurl) {
echo "alt='". $refername . "'";
}
echo "border=\"0\" /></a><br>";
echo "<a href=\"?p=referout&id=" . $id . "\">" . stripslashes($refername) . "</a><br>";
echo "Hits In: " . $referin . " | Hits Out: " . $referout . "</div>";
echo "<br><br><br>";
}
}
?>
referin.php
PHP Code:
<?PHP
if($id)
{
$prevcount = mysql_query("SELECT refin FROM refer WHERE id = '" . addslashes( $id ) . "'");
$prevcount = mysql_fetch_assoc( $prevcount );
$sql = "UPDATE refer SET refin = " . intval( $prevcount['refin'] + 1 ) . " WHERE id=" . addslashes( $id ) . "";
$result = mysql_query( $sql ) OR die( "Couldn't perform query: " . mysql_error() );
echo "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=?p=home\">";
echo "<span class='text'><div align='center'><em><strong>Loading... Please wait!</strong></em></div></span>";
}
else
{
echo "Bad ID number. But you can always go to the main site by clicking <a href='?p=home'>HERE</a>";
}
?>
Please browse through them and let me know why it might assign the id "1" for all of them!
Thanks
-Yaggles
|