Multiple Database Connections Select at Logon

Hi Team, Basically what I have done is created a website for storing my clients business data. It uses mostly forms to display the information and is uploaded and retrieved via a MySQL DB. Each client will have their own database but all database structures are the same. What I am trying to achieve is to have a login page that creates a script that connects the user to the correct database based on their login credentials. I really don’t know where to start. Have tried searching for something similar but have had no luck even tried writing a script but that didn’t seam to work.

As the clients are businesses they have staff and more than one user will have to be able to connect to each database with different authentication levels.

I was thinking something like this:
[php]

<?php // connect to your MySQL database here require_once "Agit.php"; // THIS IS THE MAIN CONNECTION SCRIPT $username = "$username"; $password = "$password"; // Build sql command $sqlCommand = "SELECT dbcon_user, dbcon_pass, dbcon_name FROM users WHERE username='$username' and password='$password' LIMIT 1"; // Execute the query here now $query = mysql_query($sqlCommand) or die (mysql_error());

while ($row = mysql_fetch_array($query)) {
// Gather all $row values into local variables
$db_database = $row[“dbcon_name”];
$db_username = $row[“dbcon_user”];
$db_password = $row[“dbcon_pass”];
}
//connect to userDB
$hostname_mycon = “$localhost”;
$database_mycon = “$db_database”;
$username_mycon = “$db_username”;
$password_mycon = “$db_password”;
$mycon = mysql_pconnect($hostname_mycon, $username_mycon, $password_mycon) or trigger_error(mysql_error(),E_USER_ERROR);
?>

UserName: Password

[/php]

I don’t mind if I have to write a seperate script for each client (business) and set it up as http://domain.com/clientname.php

Yes I am a noob but have been studying php pretty hard recently. Done about 20 tutorials in the last few weeks.

Any help or direction would be much appreciated.

Thanks in advance guys.

The problem i think is the form names, just use username and password without the $ and change it on top to $username = $_POSt[‘username’]; and $password = $_POST[‘password’];

Then the query should work.

Whenever i have trouble with queries, i echo it to see what the script is seeing. Just do echo $sqlCommand; to see what its doing.

Each client will have their own database but all database structures are the same. What I am trying to achieve is to have a login page that creates a script that connects the user to the correct database based on their login credentials

he wants also a database for every client should he be doing that he is going to have one website he is going to be writing a lot of code for each client that he has

if you have the right security for you database it should be fine just to use 1 database if all the info is the same for each client wouldn’t you say richei

Sponsor our Newsletter | Privacy Policy | Terms of Service