double query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

double query

Post 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
User avatar
grooou
Forum Newbie
Posts: 8
Joined: Tue Jun 03, 2003 1:21 pm
Location: Portugal

Post 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);
   ...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

thanks

Post 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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

hmmm

Post 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?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

woot

Post by irealms »

works, used md5 to encrypt on addition of record
Post Reply