updating two separate table columns in one if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

updating two separate table columns in one if statement

Post by dru_nasty »

'm not quite sure how to finish the following script.
Everything was working fine before, but then I realized I had to update another element of a table within the same script. I'm trying to learn php/mySQL as we speak so I may be just burning out. Some help would be appreciated. Here is the script.

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);

//start script for trial period check
$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'] == 7){
if(($row['date_added']+=(60*3)) <= time()){
mysql_query("UPDATE `registered_mem` SET`access_type_id`='1' WHERE `username`='$username'",$db_conn) or die(mysql_error());
//This line below is new to my script which was working fine already, I just don't know how to finish it.
mysql_query("UPDATE `access_priv` SET`name`='reg_user' WHERE `id`='???????'",$db_conn) or die(mysql_error());
		//end comment
		echo "your are now nothing";
}}
?>
I have a trial period set up for registered users. The time they registered is stored in the database. What I'm doing here is allowing them access for a certain time, and then once their time is up, I update some things in the site. The line I am having trouble figuring out how to write is commented out. I need to update another table named `access_priv` by setting the name to 'reg_user' WHERE their id = the number that is in the table registered_mem in the column access_priv_id. Hopefully that makes sense. Also, can I even call two separate mysql_queries within the same if statement?
I need to fix this tonight, because we've got a huge email blast going out tomorrow.
If anyone can help I thank you. I'm on aim at dru6atmac.com if anyone is willing to help outside of the forum.
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

you can call as many sql queries as you like in an if statement. it's just another line of code.

the second statement would be:

Code: Select all

mysql_query("UPDATE `access_priv` SET`name`='reg_user' WHERE `id`='$row[access_priv_id]'",$db_conn)
note that in a double quoted string, you have to leave out the quote marks of the array index. if it's confusing, use

Code: Select all

mysql_query("UPDATE `access_priv` SET`name`='reg_user' WHERE `id`='".$row['access_priv_id']."'",$db_conn)
also, you can reconstruct the nested if's into on single if statement

Code: Select all

if( $row['access_type_id'] == 7 && ($row['date_added']+=(60*3)) <= time() )
{
   //your queries
}
hope this helps.
Last edited by ryanlwh on Wed Sep 14, 2005 11:33 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

thar yer booty be in your select's result set $row, yarr..
Post Reply