每當用戶提交註冊表單時,我一次更新兩個數據庫。第一個數據庫很容易得到更新,但在第二個數據庫中沒有效果。下面是我的PHP代碼一次在php中查詢兩個數據庫
<?php
$host="localhost";
$user="aru";
$password="arus";
$ur="asus";
$passord="asus";
$db="regster";
$dbn="nsltr";
$sq=mysql_connect($host,$user,$password) or die ('mysql connecction failed'.mysql_error());
mysql_select_db($db, $sq) or die('mysql cannot select database'.mysql_error());
$dbh2 = mysql_pconnect($host, $ur, $passord, true) or die ('mysql connecction failed'.mysql_error());
mysql_select_db($dbn, $dbh2) or die('mysql cannot select database'.mysql_error());
if(isset($_POST['btnSubmit1'])){
$fullName=htmlentities(mysql_real_escape_string($_POST['nme']));
$emailID=htmlentities(mysql_real_escape_string($_POST['emil']));
$bc=htmlentities(mysql_real_escape_string($_POST['bch']));
$bn=htmlentities(mysql_real_escape_string($_POST['bnc']));
$m=htmlentities(mysql_real_escape_string($_POST['mobe']));
$em=htmlentities(mysql_real_escape_string($_POST['empy']));
$a=htmlentities(mysql_real_escape_string($_POST['ofadrs']));
$me=htmlentities(mysql_real_escape_string($_POST['msge']));
$doj=date("Y-m-d");
$sql="insert into rgst values('$emailID', '$fullName', '$bc', '$bn', '$m', '$em', '$a', '$me', '$doj')";
$rndnm= uniqid();
$log="insert into nwsletter values('$emailID', '$fullName', '$rndnm')";
if((!(mysql_query($sql,$sq))) AND (!(mysql_query($log,$dbh2)))){
echo '<script language="javascript">alert("Sorry!!! it seems you are already registered");</script>';
}
else{
echo '<script language="javascript">alert("Successfully registered.. Please check your mail address for password and other details");</script>';
}
}
?>
通過上面的代碼,我能夠更新登記數據庫但在nsltr數據庫沒有變化,也執行代碼後沒有錯誤彈出。請幫助,我是新來的PHP。在此先感謝
也許'nwsletter'應該是你的SQL語句中的'nEwsletter'?如果插入語句直接執行到數據庫而不是通過PHP腳本執行,那麼這兩種插入語句都可以工作嗎? –
另外,您的數據庫服務器是否配置爲接受持續連接?一個連接mysql_connect()'和另一個'mysql_pconnect()' –
將mysql_pconnect()更改爲mysql_connect()nwsletter表中仍然沒有變化 – user3225075