Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update code not working

Status
Not open for further replies.

NorthStarDA

IS-IT--Management
Joined
Mar 16, 2004
Messages
614
Location
US
i have a page with a record list on it, the list has links that send the ID back to the page with 'activate' or 'suspend' links. the queries are not performing, yet the die message does not show. here are the links
Code:
				<td nowrap align="center"><?php
						if($Row[user_active] == '1')
						{
							print "<a href=\"subordinates_manage.php?action=suspend&vm_user_id=" . $Row[user_id] . "\" target=\"_self\">Suspend</a>";
						}
						else
						{
							print "<a href=\"subordinates_manage.php?action=activate&vm_user_id=" . $Row[user_id] . "\" target=\"_self\">Activate</a>";
						}
					?></td>

and here is the relevant part of the code after the link is clicked
Code:
if($_GET['action'] == "activate")
		{
			$new_password = mt_rand(100000, 999999);
						
			$Query = "UPDATE phpbb_users SET phpbb_users.user_active='1', phpbb_users.user_password=MD5('$new_password') WHERE phpbb_users.user_id='$activate[$i]'";
			mysql_query($Query) or die("Error in Activate Process. ".mysql_error($Link));
			//print $Query;
						
			$Query = "SELECT username, emailaddress FROM vm_users WHERE user_id='".$activate[$i]."'";
			$Result = mysql_query($Query) or die("Error in Activate Process. ".mysql_error($Link));
						
			$Row = mysql_fetch_array($Result, MYSQL_ASSOC);
				
			$message = "Your account has been activated by your administrator. Your username is: " . $Row['username'] . " and your password is: " . $new_password . ". Please login to your account and change this default password as soon as possible.";
			mail($Row['emailaddress'], "Account activated.", $message);				
		}
			
		if($_GET['action'] == "suspend")
		{
			$Query = "UPDATE phpbb_users SET phpbb_users.user_active='0' WHERE phpbb_users.user_id='$suspend[$i]'";
			mysql_query($Query) or die("Error in Suspend Process. ".mysql_error($Link));
		}

appreciate any help


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
There seems to be a lot going on here.

For starters, use the md5 function before you get into the query. For instance,

$new_password = md5(mt_rand(100000, 999999));

$Query = "UPDATE phpbb_users SET
phpbb_users.user_active='1',
phpbb_users.user_password='$new_password'
WHERE phpbb_users.user_id = '$activate[$i]'";

Secondly, you should capture the result when you call the first query...

$result = mysql_query($Query) or die("Error in Activate Process. " . mysql_error($Link));
//print $Query;



*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
On an update query, getting a return of FALSE indicates that your SQL has an error. If your query is well-formed yet does not do anything, msql_query() will return TRUE.

Go through the standard debugging steps for databases:[ul][li]Output your generated query to the browser. Does it look right?[/li][li]Copy-and-paste the query to your preferred database tool and run the query. Does it do what you think it should?[/li][/ul]


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
hi guys and thanks for the quick responses.

i took your advice and found the problem seemed to be that $activate[$i] in the activate query has no value..

now, im a coldfusion programmer and not a PHP master yet, can anyone tell based on what I've given how that variable/structure is being set?


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
Nope.

If it's being set somewhere, it's outside of what you've posted. And $activate is not a standard PHP variable name.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It's hard to tell when we cannot see how that array is being filled.

Based on the code you displayed in your first post, if I understand your logic correctly, you may want to try $_GET['vm_user_id'] instead of $activate[$i].

This will basically perform the action requested (activate the user and set a new password) to a user whose ID was sent using the url in the previous form.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
thanks cLVlaVA,

i had tried that previously, but it threw an error
Code:
$Query = "UPDATE phpbb_users SET phpbb_users.user_active='1', phpbb_users.user_password=MD5('$new_password') WHERE phpbb_users.user_id='$_GET['vm_user_id']'";
			mysql_query($Query) or die("Error in Activate Process.

and the error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /mypathhere/user_management/subordinates_manage.php on line 69

sleipnir214, thats kinda what i figured, i'll continue to find where that array is set, i haven't come up with anything yet.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
hey guys,

i found it, the $activate was never set, it was this i needed to use

$vm_user_id = $_GET['vm_user_id'];

then do my query like so
Code:
$Query = "UPDATE phpbb_users SET phpbb_users.user_active='1', phpbb_users.user_password=MD5('$new_password') WHERE phpbb_users.user_id='$vm_user_id'";

thanks again for your help


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
Yeah, the reason is because of the single quote.

Try this instead:

$Query = "UPDATE phpbb_users SET
phpbb_users.user_active='1',
phpbb_users.user_password='$new_password'
WHERE phpbb_users.user_id = '" . $_GET['vm_user_id'] . "'";

Your single quotes were canceling eachother out.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top