Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
irealms
Forum Contributor
Posts: 215 Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds
Post
by irealms » Wed Jun 04, 2003 7:54 am
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
grooou
Forum Newbie
Posts: 8 Joined: Tue Jun 03, 2003 1:21 pm
Location: Portugal
Post
by grooou » Wed Jun 04, 2003 8:34 am
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);
...
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Jun 04, 2003 8:38 am
$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
irealms
Forum Contributor
Posts: 215 Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds
Post
by irealms » Wed Jun 04, 2003 8:56 am
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.
irealms
Forum Contributor
Posts: 215 Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds
Post
by irealms » Wed Jun 04, 2003 9:05 am
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?
irealms
Forum Contributor
Posts: 215 Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds
Post
by irealms » Wed Jun 04, 2003 9:21 am
works, used md5 to encrypt on addition of record