General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old January 9th, 2003, 07:01 AM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
Post checking if a user has already posted

hi....ive integrated a simple script into my site (and databases) so that if a user would like to add his/her websites link, then they can do it through a form... when the user clicks the submit button, the script trims it of extraneous space in the beginning of each field and then enters it into a table called links (in the db)... ive also made it so that the have to be logged in, in order to add a link and everythng works fine...but how would i make it so that the user is only allowed to add one link...?

the below is a snippet of the "process" action, to which the form is posted...

PHP Code:
<?php
    
elseif($action=="process") {
        if(
verify()) {
        global 
$forums;
        
// trim incoming data
            
$Array["address"] = trim($Array["address"]);
            
$Array["title"] = trim($Array["title"]);
            
$Array["description"] = trim($Array["description"]);
        
        
$tempname    =    $forums->member['name'];
        
        
$Link mysql_connect ($Host$User$Password);
        
$Query "INSERT into $TableName VALUES ('0', '$Array[address]', '$Array[title]', '$Array[description]', '$tempname', '1')";
        
        if (
mysql_db_query($DBName$Query$Link)) {

            print    (
"<center>");
            print    (
"Your website's link has successfully been added to our databases.\n");
            print    (
"Return to the links section by clicking <a href=\"index.php?page=links\">here</a>.  Otherwise
                        please use the navigation bar to your left.  Thank you.\n"
);
            print    (
"</center>");

        
mysql_close($Link);
        } 
// END mysql db query
        
} else { ?><body onload="where='index.php?page=links&action=addlink'; setTimeout('document.location.href=where',10000);">
        <?php
            
print    ('<center>');
            print    (
'There was a problem with your input.  Please use the link below to return to the form.  Thank you.');
            print    (
'<br>');
            print    (
'Click <a href='$PHP_SELF .'?page=links&action=addlink>here</a> to return to the links page.');
            print    (
'<br>');
            print    (
'If you do not click the link, you will automatically be redirected in 10 seconds.');
            print    (
'</center>');
            
?></body><?php
            
// END if db query was executed statement
        
// END elseif statement
?>


the form the db table follows is:

"id", "address", "title", "description", "username", "posted"

the "posted" column is either a 1, or a 0...if its a 0 then they have not posted however i think i can just get rid of that entire column if someone could enlighten me as to how to check if its a duplicate entry for the username column... thanks--
__________________
-Alexander

Reply With Quote
  #2  
Old January 9th, 2003, 07:47 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
set a cookie,...or

add an extra field to your users table

added_link ENUM 'Y','N'
__________________
-- Jason

Reply With Quote
  #3  
Old January 9th, 2003, 02:53 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
cant i just connect to the database, check if the users username is in the table and if it is display a message telling the user that they have posted already, if not then submit the info to the database...yes yes...but how??

Reply With Quote
  #4  
Old January 9th, 2003, 03:55 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
If they are already a user, then add another field type ENUM values = 'Y','N'


then when they submit,...change that value from N to Y

Reply With Quote
  #5  
Old January 10th, 2003, 06:00 AM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
okay, i see what you are saying, but wouldn't it just be easier to check if their username has already been input on the links table...keep in mind i'm not using the same tables here...ive got one tables thats got the users data when they registered (usernames, md5 passes, etc.) and then one that holds the links...so if there is a match between the username that the user is logged in as, and one on the links table, they shouldn't be allowed to post...my question is how do i accomplish this?

Reply With Quote
  #6  
Old January 10th, 2003, 09:59 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
ohhh I see,....

PHP Code:
 $sqlQ select userID  from users left join links on links.FKuserID users.userID where users.userID '{$_SESSION['userID']}' 




Reply With Quote
  #7  
Old January 10th, 2003, 02:38 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
i cant understand that...but im sure if/when i get it, it will help, thanks--

Reply With Quote
  #8  
Old January 10th, 2003, 05:26 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
heres what that is doing.

You know the user ID, either by a cookie or session. so you query your user table and the links table looking for a match in userID.

Make sense?

If a match exists in that query
PHP Code:
if(mysql_num_rows($sqlQ) == 1


Then you know what to do there.

make sense?

Last edited by Taelo : January 10th, 2003 at 06:51 PM.

Reply With Quote
  #9  
Old January 10th, 2003, 06:07 PM
kylie kylie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 19 kylie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Its actually quite simple fellas. Firstly add a field called userId to your links table. When a user adds a link, also store there user Id in that table.

Then to make sure that they can post again, you do the following

PHP Code:
 $result mysql_query("SELECT count(*) FROM $tableName WHERE userId = '$userId'");

$post = (mysql_result($result00) == true false)

if(
$post)
//run insert query here
else
//already posted 


as simple as that.

Reply With Quote
  #10  
Old January 11th, 2003, 02:23 AM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
genuis... thanks kylie and taelo for the help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > checking if a user has already posted


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 5 hosted by Hostway