Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
dru_nasty
Forum Commoner
Posts: 81 Joined: Sat Sep 10, 2005 10:26 am
Post
by dru_nasty » Sat Sep 10, 2005 10:33 am
Hi, I'm new to php/mysql and can't quite figure out why the following script isn't working. It echoes properly but doesn't change the users acces_type_id in the database. The basic plan is when someone registers on the site, I stamp the time() that they registered and store it in the table registered_mem along with all their other user info. Then from that point of registration they have all access to our registered members section of the site. This is allowed with an access_type_id of 14. Then after one weeks time (actually in the below code i have it set for 3 minutes for testing purposes), when they try to access things again, they are changed from a 14 to a 1 for their access_type_id.
The echoe works as I said, but when I check the db the access_type_id is still 14. I have no idea whats going wrong.
Thanks in advance.
Code: Select all
<?
include_once('/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php');
$username = $HTTP_COOKIE_VARS['log']['username'];
$db_conn = five_connect_db();
mysql_select_db('fivestar',$db_conn);
$sql = "SELECT * FROM `registered_mem` WHERE `username`='$username'";
$result = mysql_query($sql, $db_conn) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if($row['access_type_id'] == 14){
if(($row['date_added']+=(60*3)) <= time()){
mysql_query("UPDATE `registered_mem` SET(`access_type_id`='1') WHERE `username`='$username'",$db_conn);
echo "Your access is now 1";
}
}?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 10, 2005 10:38 am
are you absolutely sure your query is syntacticly correct? try this change
Code: Select all
mysql_query("UPDATE `registered_mem` SET(`access_type_id`='1') WHERE `username`='$username'",$db_conn) or die(mysql_error());
dru_nasty
Forum Commoner
Posts: 81 Joined: Sat Sep 10, 2005 10:26 am
Post
by dru_nasty » Sat Sep 10, 2005 10:48 am
I changed that line, and now i get this error:
You have an error in your SQL syntax near '(`access_type_id`='1') WHERE `username`='amanda'' at line 1
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 10, 2005 10:49 am
remove the parens.
dru_nasty
Forum Commoner
Posts: 81 Joined: Sat Sep 10, 2005 10:26 am
Post
by dru_nasty » Sat Sep 10, 2005 10:52 am
around what exactly?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 10, 2005 10:57 am
where it says the error is
dru_nasty
Forum Commoner
Posts: 81 Joined: Sat Sep 10, 2005 10:26 am
Post
by dru_nasty » Sat Sep 10, 2005 11:01 am
I'm sorry, I don't know what should go and what should stay in this line;
Code: Select all
mysql_query("UPDATE `registered_mem` SET(`access_type_id`='1') WHERE `username`='$username'",$db_conn) or die(mysql_error());
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 10, 2005 11:04 am
Code: Select all
mysql_query("UPDATE `registered_mem` SET `access_type_id`='1' WHERE `username`='$username'",$db_conn) or die(mysql_error());
dru_nasty
Forum Commoner
Posts: 81 Joined: Sat Sep 10, 2005 10:26 am
Post
by dru_nasty » Sat Sep 10, 2005 11:12 am
Ahh, I was thinking of quotes, not parens, sorry.
That did the trick! You made my day, thank you so much!