Multiple database
Posted: Thu Jun 30, 2005 1:42 am
Hi all,
I am trying to connect two database one after another like below:
[syntax=php]$host="localhost";
$user="root";
$passwd="";
$db="airfare2pak";
$new_con=@mysql_connect($host,$user,$passwd) or
die("Cannot connect to database");
mysql_select_db($db,$new_con)or
die("Could not find database");
mysql_close($new_con);
$host="localhost";
$user="root";
$passwd="";
$db="forum";
$new_con1=@mysql_connect($host,$user,$passwd) or
die("Cannot connect to database");
mysql_select_db($db,$new_con1)or
die("Could not find database");
?>[/syntax]
but it is showing "no database selected" error. Where I am wrong? give me some suggestions.
What is happening is that I am using IPB in my site where registered users from IPB will be able to enjoy shopping in my site. The problem is that I cannot identify where it is updating the IPB dtabase,then what should I do? code of my cart is as follows:
[syntax=php]<?php
$name=$_REQUEST['n'];
$amount=$_REQUEST['a'];
$no=$_REQUEST['no'];
require_once "../ipbsdk/ipbsdk_class.inc.php";
$SDK =& new IPBSDK();
$info = $SDK->get_info();
// Generate Bar Content
$member_name = $info['name'];
$member_id = $info['id'];
$group=$info['mgroup'];
if ($SDK->is_loggedin()) {
include('af2p_db.php');
include('func.php');
//include('forum_con.php');
$table=fnTableExists($member_name);
?>
<html><head><title>My Cart-Shopping Cart</title></head>
<body bgcolor="#FF6699">
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="franck-reg@paypal.com">
<input type="hidden" name="item_name_1" value="<? echo $name; ?>">
<input type="hidden" name="amount_1" value="<? echo $amount; ?>">
<input type="hidden" name="item_name_2" value="Item Name2">
<input type="hidden" name="amount_2" value="2.00">
<input type="hidden" name="page_style" value="ach">
<div align="center">
<center>
<table border="1" cellpadding="2" cellspacing="0" width="56%">
<tr>
<td width="143%" colspan="3">
<p align="center">Your Cart</td>
</tr>
<tr>
<td width="56%">Name</td>
<td width="78%">Amount</td>
<td width="72%">Quantity</td>
</tr>
<tr>
<td width="56%"><? echo $name;?></td>
<td width="78%">$<? echo $amount; ?></td>
<td width="72%"><input type="text" name="T1"></td>
<? if($table)
{$q=$_POST['T1'];
$ins="insert into `adminac` values('$name',$no,$q,$amount,0)";
mysql_query($ins) or
die(mysql_error());
$qr="select * from `adminac`";
$rsc=mysql_query($qr) or
die(mysql_error());
while ($row=mysql_fetch_array($rsc)) {
?>
<td width="56%"><? echo $row[0];?></td>
<td width="78%">$<? echo $row[3]; ?></td>
<td width="72%"><input type="text" name="<? echo $row[2];?>"></td>
<?}
}
else
{$crt="CREATE TABLE `<?echo $member_name;?>` (
`item_name` VARCHAR( 25 ) NOT NULL ,
`item_no` INT( 10 ) NOT NULL ,
`quantity` INT( 10 ) NOT NULL ,
`amount` FLOAT( 10 ) NOT NULL ,
`tot_amount` FLOAT( 10 ) not null
)";
mysql_query($crt) or
die(mysql_error());
$q=$_POST['T1'];
$ins="insert into `<? echo $member_name;?>` values('$name',$no,$q,$amount,0)";
mysql_query($ins) or
die(mysql_error());
}?>
</tr>
<tr>
<td width="143%" colspan="3">
<p align="center">
<input type="submit" value="Upload Cart">
</td>
</tr>
</table>
</center>
</div>
</form>
<?
}
else
echo "You are not logged in";
?>[/syntax]
What should I do solve the problem?
I am trying to connect two database one after another like below:
[syntax=php]$host="localhost";
$user="root";
$passwd="";
$db="airfare2pak";
$new_con=@mysql_connect($host,$user,$passwd) or
die("Cannot connect to database");
mysql_select_db($db,$new_con)or
die("Could not find database");
mysql_close($new_con);
$host="localhost";
$user="root";
$passwd="";
$db="forum";
$new_con1=@mysql_connect($host,$user,$passwd) or
die("Cannot connect to database");
mysql_select_db($db,$new_con1)or
die("Could not find database");
?>[/syntax]
but it is showing "no database selected" error. Where I am wrong? give me some suggestions.
What is happening is that I am using IPB in my site where registered users from IPB will be able to enjoy shopping in my site. The problem is that I cannot identify where it is updating the IPB dtabase,then what should I do? code of my cart is as follows:
[syntax=php]<?php
$name=$_REQUEST['n'];
$amount=$_REQUEST['a'];
$no=$_REQUEST['no'];
require_once "../ipbsdk/ipbsdk_class.inc.php";
$SDK =& new IPBSDK();
$info = $SDK->get_info();
// Generate Bar Content
$member_name = $info['name'];
$member_id = $info['id'];
$group=$info['mgroup'];
if ($SDK->is_loggedin()) {
include('af2p_db.php');
include('func.php');
//include('forum_con.php');
$table=fnTableExists($member_name);
?>
<html><head><title>My Cart-Shopping Cart</title></head>
<body bgcolor="#FF6699">
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="franck-reg@paypal.com">
<input type="hidden" name="item_name_1" value="<? echo $name; ?>">
<input type="hidden" name="amount_1" value="<? echo $amount; ?>">
<input type="hidden" name="item_name_2" value="Item Name2">
<input type="hidden" name="amount_2" value="2.00">
<input type="hidden" name="page_style" value="ach">
<div align="center">
<center>
<table border="1" cellpadding="2" cellspacing="0" width="56%">
<tr>
<td width="143%" colspan="3">
<p align="center">Your Cart</td>
</tr>
<tr>
<td width="56%">Name</td>
<td width="78%">Amount</td>
<td width="72%">Quantity</td>
</tr>
<tr>
<td width="56%"><? echo $name;?></td>
<td width="78%">$<? echo $amount; ?></td>
<td width="72%"><input type="text" name="T1"></td>
<? if($table)
{$q=$_POST['T1'];
$ins="insert into `adminac` values('$name',$no,$q,$amount,0)";
mysql_query($ins) or
die(mysql_error());
$qr="select * from `adminac`";
$rsc=mysql_query($qr) or
die(mysql_error());
while ($row=mysql_fetch_array($rsc)) {
?>
<td width="56%"><? echo $row[0];?></td>
<td width="78%">$<? echo $row[3]; ?></td>
<td width="72%"><input type="text" name="<? echo $row[2];?>"></td>
<?}
}
else
{$crt="CREATE TABLE `<?echo $member_name;?>` (
`item_name` VARCHAR( 25 ) NOT NULL ,
`item_no` INT( 10 ) NOT NULL ,
`quantity` INT( 10 ) NOT NULL ,
`amount` FLOAT( 10 ) NOT NULL ,
`tot_amount` FLOAT( 10 ) not null
)";
mysql_query($crt) or
die(mysql_error());
$q=$_POST['T1'];
$ins="insert into `<? echo $member_name;?>` values('$name',$no,$q,$amount,0)";
mysql_query($ins) or
die(mysql_error());
}?>
</tr>
<tr>
<td width="143%" colspan="3">
<p align="center">
<input type="submit" value="Upload Cart">
</td>
</tr>
</table>
</center>
</div>
</form>
<?
}
else
echo "You are not logged in";
?>[/syntax]
What should I do solve the problem?