Variable only being used once

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
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Variable only being used once

Post by tristanlee85 »

Code: Select all

//Create the forum
	$sql = "INSERT INTO phpbb_forums 
		VALUES ('$forum_id', '1', '$new_member', '$description', '0', '$new_forum_order', '0', '0', '0', '', '0', '0', '0', 			'3', '1', '1', '3', '3', '3', '1', '1', '1', '-1', '1', '29')";
	mysql_query($sql);

	//Set the group values
	$sql = "INSERT INTO phpbb_groups
		VALUES ('$group_id', '1', '', 'Personal User', '0', '1')";
	mysql_query($sql);

	$sql = "INSERT INTO phpbb_user_groups
		VALUES ('$group_id', '$user_id', '0')";
	mysql_query($sql);

	//Make the user moderator of his/her forum
	$sql = "INSERT INTO phpbb_auth_access
		VALUES ('$group_id', '$forum_id', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0')";
	mysql_query($sql);
The variable $group_id is to be used in 3 different queries. When I run the script, it's used in the first query, but then in the last 2 queries, it inserts 0 instead of the $group_id variable. Why is this?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Echo out each query....
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

I don't understand what you are saying.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

he means echo out your queries... not as a solution, but to help us troubleshoot the problem...

Code: Select all

        //Create the forum
        $sql = "INSERT INTO phpbb_forums
                VALUES ('$forum_id', '1', '$new_member', '$description', '0', '$new_forum_order', '0', '0', '0', '', '0', '0', '0',             '3', '1', '1', '3', '3', '3', '1', '1', '1', '-1', '1', '29')";
        echo $sql . "<BR>";
        mysql_query($sql);

        //Set the group values
        $sql = "INSERT INTO phpbb_groups
                VALUES ('$group_id', '1', '', 'Personal User', '0', '1')";
        mysql_query($sql);
        echo $sql . "<BR>";

        $sql = "INSERT INTO phpbb_user_groups
                VALUES ('$group_id', '$user_id', '0')";
        mysql_query($sql);
        echo $sql . "<BR>";

        //Make the user moderator of his/her forum
        $sql = "INSERT INTO phpbb_auth_access
                VALUES ('$group_id', '$forum_id', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0')";
        echo $sql . "<BR>";
        mysql_query($sql);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: Variable only being used once

Post by hawleyjr »

Code: Select all

//Set the group values
	$sql = "INSERT INTO phpbb_groups
		VALUES ('$group_id', '1', '', 'Personal User', '0', '1')";
	mysql_query($sql);
echo '<hr>' . $qry;
	$sql = "INSERT INTO phpbb_user_groups
		VALUES ('$group_id', '$user_id', '0')";
	mysql_query($sql);
echo '<hr>' . $qry;
	//Make the user moderator of his/her forum
	$sql = "INSERT INTO phpbb_auth_access
		VALUES ('$group_id', '$forum_id', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0')";
	mysql_query($sql); 
echo '<hr>' . $qry;
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Hmm. It just started working... not exactly sure what I changed. I echo'd it out like you said and the queries were right. I deleted a few records in the database and I think it got my counts off. That's why some of it was executing right and some wasn't. Thanks all.
Post Reply