當我使用mysql_select_db()我的$ _ POST變量拿出空的,如果我把它註釋掉然後我$ _ POST變量是不錯,但我的查詢可以執行。 (未選擇數據庫)。我確實有我的連接文件。
這裏是我的代碼的崩潰:你conn1.php文件中
<?php
require_once('connections/conn1.php');
include('functions.php');
print_r ($_POST);//Outputs "Array()" to the screen
if(isset($_POST['Login']))
{
mysql_select_db($database_conn1, $conn1);
// if this line is commented out then the print_r($_POST)
//above outputs all the correct information.
$select = 'SELECT record_id, username, active FROM table1 WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"';
$query = mysql_query($select, $conn1) or die(mysql_error());
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table>
<tr>
<td align="right">Username</td>
<td><input type="text" id="username" name="username" size="32" value="" />
</td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" id="password" name="password" size="32" value="" />
</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Login" value="Login" /></td>
</tr>
</table>
你有'mysql_connect()'集合嗎?你有沒有嘗試在'mysql_select_db()'的末尾添加'die(mysql_error())'以確保它不會死? – Biotox 2012-01-16 19:20:32
我添加'或死(mysql_error());'到mysql_select_db()的末尾,沒有任何改變。我的'require_once('connections/conn1.php');'包括代碼我的'mysql_connect()'以及主機名,數據庫,用戶名和密碼,我也有一個''或die(mysql_error());'at 'mysql_connect'的結尾。我的意思是我的$ _ POST變量是空的是,當我衝線'的print_r($ _ POST); //輸出「陣列()」屏幕 '我看到的是輸出到屏幕上是'陣列() '它應該輸出一個包含我所有後期變量的數組。 – 2012-01-16 19:30:12
當表單被提交時,而不是之前的情況就是這種情況,在這種情況下mysql_select_db()不會被調用,因爲它取決於被設置的$ _POST ['login']索引,即當表單是提交,因此,當$ _POST數組不是空的 – 2012-01-16 19:36:48