Page 1 of 1

Mutplie Queries in same script?!

Posted: Mon Dec 30, 2002 5:17 pm
by Elmseeker
Hi,

Due to the kind of site I am in I have user levels and I need these broken down even further like 1-3 is one group 4-6 is another group and 7-10 is yet another group. I have 4 tables to handle of this broken down in such a way that 1 DB contains the primary login data for <b>ALL</B> users, such as user name, password (encrypted of course), and ID and whther they are logged in or not...

the other 3 tables contain information specific to the type of account, which are:
  • Children
  • Parents and Teachers
  • Site Staff/Volunteers
The way I am doing this is when someone fills out the form to login it should query the main login table called m_login, check the user name, pass and user level...then it should use the userlevel to determine which table to query next to get the information that will be saved in their session. here is the code I am currently working with and for some reason $_SESSION["login"] always seems to be populated with the information from the FIRST query...please ignore the comments, they're just there so I don't lsoe track of the changes I am making hehe :)...

Code: Select all

<?
$connection = mysql_connect("$host","$sqluser","$pass");
if ($connection == false) {
        echo mysql_errno . ": " . mysql_error() . "<br>";
        exit;
}
mysql_select_db('kidstop');   

// now uses m_login which will check user level and grab info from
// appropriate table to register into the session...
$query = "SELECT * FROM m_login WHERE u_name = '$name'";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {
if ($name == $row["u_name"]) {
if (md5($pass1) == $row["u_pass"]) {
$ulvl = $row["u_level"];   
mysql_free_result($result);
if ( $ulvl << 3 ) {
$query = "SELECT * FROM k_main WHERE u_name = '$name'";
$result = mysql_query($query);
$login = $row;
}
if ( $ulvl >> 3 && $row["u_level"] << 7 ) {
$query = "SELECT * FROM p_login WHERE u_name = '$name'";
$result = mysql_query($query);
$login = $row;
}
if ( $ulvl >> 7) {
$query = "SELECT * FROM staff WHERE u_name = '$name'";
$result = mysql_query($query);
$login = $row;
}
 
session_register('login'); // Now called after all DB calls have been parsed to make sure we have coorect info for acocunt type.
echo "<BR>You are now logged in! <A HREF="index.php">Click Here</A> to continue!<BR>";
?>
$name is defined, it is what was passed by the form, that is handled up above and is working properly...amaing isn't it?! hehe...

Thanks alot folks!

Posted: Tue Dec 31, 2002 3:03 pm
by Elmseeker
Bump!

Posted: Wed Jan 01, 2003 6:39 pm
by Beans
Check out a script I made (vSignup 2.1) at Hotscripts.com. It might be what you need. The password is currently not encrypted though. You can include the encryption if you want.

Posted: Thu Jan 02, 2003 12:50 pm
by Gen-ik
it is what was passed by the form, that is handled up above and is working properly...amaing isn't it?!
What's amazing!?

Try programming a multi-level Forum such as this one... then look at your script again... you won't be saying "amazing!"

:roll:

Posted: Thu Jan 02, 2003 2:19 pm
by Elmseeker
rofl! Amazing that something I wrote was working *grin*.

Anyway I finally got it working through some trial and error. Now I am having a hard time getting it to update some stuff properly but I have the feeling that will be coming soon as well, probably just a typo somewhere, if not I'll post here later on and see if anyone has any ideas...Thanks a bunch folks!

Posted: Thu Jan 02, 2003 2:37 pm
by Gen-ik
Hehe! :D

You probably already know this but to update a mysql table just do something similar to this..

Code: Select all

<?php

$old_name="Just Bob";

$new_name="Bob Builder";

mysql_query(" UPDATE `your_table` SET `name`='$new_name' WHERE `name`='$old_name' ");

?>

Good luck with the script :)

Posted: Thu Jan 02, 2003 2:51 pm
by Elmseeker
Yeah,

It's not the actual updating I am having trouble with though, it's getting it to update proerly at the right time...literally, here I'll show ya when I mean...

Code: Select all

<?
$timenow = time();   
   
$query_ro = "SELECT * FROM m_login where 1";
$result_ro = mysql_db_query("$dbase",$query_ro);
echo $timenow;
echo " minus ".$row["la_time"]." equals ".$timenow - $row["la_time"];
while($row =mysql_fetch_array($result_ro)){
$uid = $row["ID"];
if ( ( $timenow-$row["la_time"] ) > 3600 ) {
$query_ro2 = "UPDATE m_login SET logged=0 where ID='$uid'";
$result_ro2 = mysql_query($query_ro2);
$query_ro3 = "UPDATE m_login SET la_time=0 where ID='$uid'";
$result_ro3 = mysql_query($query_ro3);
}
}
?>
It just doesn't seem to want to update those rows at the proper times, for some reason it always thinks the time difference is the same as time() *cries*

Posted: Thu Jan 02, 2003 4:10 pm
by Elmseeker
Well...got this one working too now, told ya I'd probably get it tonight...:)