Current location: Hot Scripts Forums » Other Discussions » Database » php code


php code

Reply
  #1 (permalink)  
Old 10-05-06, 08:23 AM
phpfreek phpfreek is offline
Wannabe Coder
 
Join Date: Feb 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
php code

Hello, below is a code that will update database information :

PHP Code:

$query="UPDATE $usernamee SET rank=rank+2"
$result mysql_query($query) or die(mysql_error()); 
I will let users update their database info with these 2 lines of code;
However, this is not my problem, i would like users to be able to update info only each 2 minutes, that means i want to restrict update of database info for a period of 2 minutes after the info is updated last.

Does anyone know a code that cn do that ?
Thank you in advance.
Best Regards;
PHPFREEK
Reply With Quote
  #2 (permalink)  
Old 10-05-06, 01:39 PM
mousegu mousegu is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
You have to add a field to the databas that will hold a datetime stamp.
Then, before you update, select the datetime stamp from the database, check to see if its older than two minutes, if it is then update the database and add the new timestamp.

Hope that helps..
__________________
SSP
Professional Web Design

SSP Website
Reply With Quote
  #3 (permalink)  
Old 10-05-06, 01:55 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Add an INT field to the table and change your update query to something like this.
PHP Code:

$query="UPDATE $usernamee SET rank=rank+2, lastupdate ="time(); 

So that it stores the time it has been updated for the last time.

Now the next time when you want to update, you check when it has been updated for the last time.

PHP Code:

$query mysql_query("SELECT lastupdate FROM $usernamee");

$userinfo mysql_fetch_array($query);

if (
$userinfo['lastupdate'] > (time() - 120))
{
    echo 
'Please wait 2 minutes before updating your profile again.';
}
else
{
    
// Update profile


EDIT:

And topic moved to database.
Reply With Quote
  #4 (permalink)  
Old 10-05-06, 02:54 PM
phpfreek phpfreek is offline
Wannabe Coder
 
Join Date: Feb 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
:|
I have absolutely no idea what to SAY ... it's like the 10th time you help me with my projects ... all i can do is thank you

I really appreciate it bro, it worked perfectly ! ...

Thank again ...
Best Regards;
PHPFREEK
Quote:
Originally Posted by nico_swd
Add an INT field to the table and change your update query to something like this.
PHP Code:

$query="UPDATE $usernamee SET rank=rank+2, lastupdate ="time(); 

So that it stores the time it has been updated for the last time.

Now the next time when you want to update, you check when it has been updated for the last time.

PHP Code:

$query mysql_query("SELECT lastupdate FROM $usernamee");

$userinfo mysql_fetch_array($query);

if (
$userinfo['lastupdate'] > (time() - 120))
{
    echo 
'Please wait 2 minutes before updating your profile again.';
}
else
{
    
// Update profile


EDIT:

And topic moved to database.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI Code Converting to PHP - need help PHP Warner PHP 4 03-29-06 07:32 AM
PHP Code files single lined Kobra PHP 3 01-07-06 09:02 AM
php/apacher server displaying php code doctork1 PHP 2 12-15-04 12:10 PM
Need Help In PHP Programming for a single code suggestion !! CyberRomeo PHP 1 11-27-04 10:38 AM
Need help with PHP code rodman PHP 0 05-21-04 09:28 AM


All times are GMT -5. The time now is 04:56 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.