Jump to content

Archived

This topic is now archived and is closed to further replies.

Craziest

Calling two databases in one login form

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....

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
huh, .....and I always thought u had to do a join  (shrugs)  ...learn something new everyday I suppose

Share this post


Link to post
Share on other sites

×

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.