SunQuest
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 4th, 2005, 07:11 AM
DKing DKing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 59 DKing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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'] + ) . " 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

Reply With Quote
  #2  
Old December 26th, 2006, 10:41 AM
SKDevelopment SKDevelopment is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 659 SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 46 m 25 sec
Reputation Power: 169
These lines:
PHP Code:
 $result mysql_query("SELECT * FROM `refer`");
    
$myrow mysql_fetch_array($result);
    
$id $myrow["id"]; 

Always return the id of the 1st (I mean topmost in the returned recordset) row. To return the id of the most recently inserted row you could e.g. make your id field something like
Code:
id INT AUTO_INCREMENT PRIMARY KEY

in the CREATE TABLE syntax and use e.g. the line (not checked):
PHP Code:
 $result mysql_query("SELECT * FROM `refer` WHERE id=LAST_INSERT_ID()"); 

instead of
PHP Code:
 $result mysql_query("SELECT * FROM `refer`"); 
__________________
PHP Programmer

Reply With Quote
  #3  
Old December 26th, 2006, 10:51 AM
sejohnson sejohnson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Location: Appleton, WI
Posts: 124 sejohnson User rank is Corporal (100 - 500 Reputation Level)sejohnson User rank is Corporal (100 - 500 Reputation Level)sejohnson User rank is Corporal (100 - 500 Reputation Level)sejohnson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 4 h 2 m 43 sec
Reputation Power: 3
looks like an old post to me.. it was posted in febuary of 2005
Comments on this post
SKDevelopment agrees: Yes, you are right ... Sorry
__________________
Tervoo

Reply With Quote
  #4  
Old December 26th, 2006, 10:56 AM
SKDevelopment SKDevelopment is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 659 SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level)SKDevelopment User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 46 m 25 sec
Reputation Power: 169
Oh... Sorry!!! there was a spamming post in the thread (probably will be deleted by the moderators shortly), after which the thread got to the top. And I answered without looking at the date of the original post. Will have to pay more attention in the future.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Link Referral System


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway