Jump to content

Calling two databases in one login form


Craziest

Recommended Posts

i need to have two databases while am login. one fake and one original . if
the fake login and the password is true then it will redirect him to another
page. so i need to have two require statements so it can check both databas
es,,
if its possible tht would be great...
i will be greatful for any comments....
Link to comment
Share on other sites

Following is a quote from an entry in the php.net documentation for mysql_select_db:

[quote]Originally Posted by
matsko at rogers dot com 10-May-2006 09:19
Just incase the mysql_select_db() function still won't work with multiple database connections (as has happened to me before).

$dbh1 = mysql_pconnect($host,$user,$pass);
$dbh2 = mysql_pconnect($host,$user,$pass);

You could do this...

mysql_query("USE database1",$dbh1);
mysql_query("Use database2",$dbh2);

This does the same thing as the mysql_select_db() function...

or this...

You don't even have to select the database for each connection.

mysql_query("SELECT * FROM database1.table",$dbh1);
mysql_query("SELECT * FROM database2.table",$dbh2);
[/quote]
Link to comment
Share on other sites

[code]
<?php

if($name && $password){

if($_POST['submit']) {

$db1=mysql_connect("xxxx","xxxxx","xxxxx");

$result1=mysql_select_db("xxxxx",$db1);

$query1="select * from  xxxxx where id='$id'":

$resulted1=mysql_query($query1);

if(mysql_num_rows($resulted1)){

echo " your logged into database 1";

}else{

$db2=mysql_connect("xxxx","xxxxx","xxxxx");

$result2=mysql_select_db("xxxxx",$db2);

$query2="select * from xxxxxxx where id='$id'":

$resulted2=mysql_query($query2);

if(mysql_num_rows($resulted2)){

echo " your logged into database 2";
}
}
  }else{

echo " Sorry but we have no deatail of your account please register thank you.";

include("register.php");

}
?>
[/code]
Link to comment
Share on other sites

Thanks guys for the quick reply,im still getting afew problems since im using wordpress and adding this feature to the login form.
this is what i added
wp-login.php
[code]<?php

require('./wp-config.php');

function login($username, $password, $already_md5 = false) {

global $wpdb, $wpdb1, $error, $tableusers;
if($username && $password){

if($_POST['submit']) {

$wpdb=mysql_connect($server,$loginsql,$passsql);

$query = "SELECT ID, user_login, user_pass FROM $tableusers, WHERE user_login = '$username'";

$login =mysql_query($query);

}else{

$wpdb2=mysql_connect($server1,$loginsql1,$passsql1);

$query2 = "SELECT ID, user_login, user_pass FROM $tableusers, WHERE user_login = '$username'";

$login =mysql_query($query2);[/code]

and in the wp-config.php
[code]// ** MySQL settings ** //
define('DB_NAME', 'wp1');    // The name of the database
define('DB_USER', 'root');    // Your MySQL username
define('DB_PASSWORD', ''); // ...and password
define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value

define('DB_NAME1', 'wp1fake');    // The name of the database
define('DB_USER1', 'root');    // Your MySQL username
define('DB_PASSWORD1', ''); // ...and password
define('DB_HOST1', 'localhost');    // 99% chance you won't need to change this value

$table_prefix  = 'wp_';  // example: 'wp_' or 'b2' or 'mylogin_'

define ('WPLANG', '');

/* Stop editing */

$server = DB_HOST;
$loginsql = DB_USER;
$passsql = DB_PASSWORD;
$base = DB_NAME;

/* Stop editing */

$server1 = DB_HOST1;
$loginsql1 = DB_USER1;
$passsql1 = DB_PASSWORD1;
$base1 = DB_NAME1;
[/code]
When i enter the username and pass in wp-login.php it says
Warning: mysql_connect(): Access denied for user 'ODBC'@'localhost' (using password: NO) in c:\appserv\www\wp\wp-login.php on line 14
which is [code]$query = "SELECT ID, user_login, user_pass FROM $tableusers, WHERE user_login = '$username'";[/code]
Sorry im brand new in php :(  please excuse my silly mistakes.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.