Page 1 of 1

double query

Posted: Wed Jun 04, 2003 7:54 am
by irealms
i have a button that when clicked will approve a user by changing a field in a database. I have some forums and as i'm having trouble tying the 2 logins together i'm trying to set it so that when admin approves a member it will add them to the forum database so they can log onto the forum.

First when i was just approving them i had

Code: Select all

<?php
if (isset($_POST['userapp']))
{
	$userapp = "UPDATE users set approved = '1' where username = '$_POST[useredit]'"; 
	$resultapp = mysql_query($userapp, $db_conn) or die("query [$query] failed: ".mysql_error()); 
}

?>
which worked fine. Now i've changed it to

Code: Select all

<?php

if (isset($_POST['userapp']))
{
	$userapp = "UPDATE users set approved = '1' where username = '$_POST[useredit]'"; 
	$resultapp = mysql_query($userapp, $db_conn) or die("query [$query] failed: ".mysql_error()); 
	$addtoforum = "SELECT * FROM users where username = '$_POST[useredit]'";
	$add1 = mysql_query($addtoforum, $db_conn) or die("query [$query] failed: ".mysql_error());
    $row = mysql_fetch_assoc($addl);
	$fuser = $row['username'];
	$fname = $row['username'];
	$fpass = $row['passwd'];
	$fmail = $row['email'];
	if ($row==1)
	{
		$adduser = "INSERT INTO forum_auth (name,username,password,email) VALUES ('$fname','$fuser','$fpass','$fmail')";
		$done = mysql_query($adduser, $db_conn) or die("query [$query] failed: ".mysql_error()); 
	}

}

?>
#]

Whilst i get no errors it also isn't adding the user to the forums

Posted: Wed Jun 04, 2003 8:34 am
by grooou
Hi, i think that you just have to change $addl by $add1 in the "$row =" statement

Code: Select all

...
   $add1 = mysql_query($addtoforum, $db_conn) or die("query [$query] failed: ".mysql_error());
    $row = mysql_fetch_assoc($addl);
   ...

Posted: Wed Jun 04, 2003 8:38 am
by twigletmac

Code: Select all

if ($row==1)
$row is an array - are you trying to check that the record exists? If so try:

Code: Select all

<?php 

if (isset($_POST['userapp'])) { 
	$userapp = "UPDATE users set approved = '1' where username = '$_POST[useredit]'"; 
	@mysql_query($userapp, $db_conn) or die("query [$userapp] failed: ".mysql_error()); 
	$addtoforum = "SELECT username, passwd, email FROM users where username = '$_POST[useredit]'"; 
	$add1 = mysql_query($addtoforum, $db_conn) or die("query [$add1] failed: ".mysql_error()); 
	if (mysql_num_rows($add1) == 1) {
		$row = mysql_fetch_assoc($add1); 
		$fuser = $row['username']; 
		/* you are setting $fuser and $fname to the same thing? */
		$fname = $row['username']; 
		$fpass = $row['passwd']; 
		$fmail = $row['email']; 

		$adduser = "INSERT INTO forum_auth (name,username,password,email) VALUES ('$fname','$fuser','$fpass','$fmail')"; 
		$done = mysql_query($adduser, $db_conn) or die("query [$adduser] failed: ".mysql_error()); 
	}
}

?>
Mac

thanks

Posted: Wed Jun 04, 2003 8:56 am
by irealms
seems to work atm, testing it more now :)

the reason 2 of the variables are the same is the phorum script i have uses a username and a realname. I am only adding this script as i can't figure out how to link phorum's login to my site login.

hmmm

Posted: Wed Jun 04, 2003 9:05 am
by irealms
have a problem, it enters the user into the database but doesn't recognise the password when you login. I looked in the database and the forum password is encrypted usually, then ones entered by the script i'm adding are not. how do i make it encrypt the password when it's entered into the database?

woot

Posted: Wed Jun 04, 2003 9:21 am
by irealms
works, used md5 to encrypt on addition of record