Jump to content


Photo

Calling two databases in one login form


  • Please log in to reply
4 replies to this topic

#1 Craziest

Craziest
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 August 2006 - 08:32 PM

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

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 05 August 2006 - 08:37 PM

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

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);


RTFM is an almost extinct art form, it should be subsidized.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 August 2006 - 08:44 PM

<?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");

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Craziest

Craziest
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 August 2006 - 10:44 PM

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
<?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);

and in the wp-config.php
// ** 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;
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
$query = "SELECT ID, user_login, user_pass FROM $tableusers, WHERE user_login = '$username'";
Sorry im brand new in php :(  please excuse my silly mistakes.


#5 bubazoo

bubazoo
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationWarsaw, IN

Posted 06 August 2006 - 05:30 AM

huh, .....and I always thought u had to do a join  (shrugs)  ...learn something new everyday I suppose
[!--sizeo:3--][span style="font-size:12pt;line-height:100%"][!--/sizeo--]
[a href="http://www.tcoburn.com" target="_blank"]http://www.tcoburn.com[/a] -- personal site
[a href="http://www.crohnsdaily.com" target="_blank"]http://www.crohnsdaily.com[/a] -- Crohn's Disease support Forums
[!--sizec--][/span][!--/sizec--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users