2012-01-16 35 views
2

當我使用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> 

+0

你有'mysql_connect()'集合嗎?你有沒有嘗試在'mysql_select_db()'的末尾添加'die(mysql_error())'以確保它不會死? – Biotox 2012-01-16 19:20:32

+0

我添加'或死(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

+0

當表單被提交時,而不是之前的情況就是這種情況,在這種情況下mysql_select_db()不會被調用,因爲它取決於被設置的$ _POST ['login']索引,即當表單是提交,因此,當$ _POST數組不是空的 – 2012-01-16 19:36:48

回答

0

認沽mysql_select_db($ database_conn1,$ conn1的)。

+0

我提交表單後,該行'如果(isset($ _ POST [「登錄」])) '出現假的,所以檢查值正從我的形式通過了什麼,我放線'的print_r($ _ POST ); //將「Array()」輸出到屏幕上,它仍然以空數組的形式出現。我將嘗試將'mysql_select_db()'放在我的conn1.php文件中。 – 2012-01-16 19:53:06

+0

將mysql_select_db()添加到我的conn1.php文件中並沒有改變任何內容。表單提交後,$ _POST變量仍然以空數組的形式出現。 – 2012-01-16 19:54:56

0

我有幾乎同樣的問題...查一查這裏「由$ _ POST-值不行發送數據庫名稱」。 我用if(isset($ _POST ['dbName'])){php-code}和它的工作方式圍繞我的洞php代碼:)它需要我約8小時!我希望這會成爲一個人!