mysql_select_db()を使用すると、$ _POST変数が空になります。コメントアウトすると、$ _POST変数は正常ですが、クエリが実行できます。 (データベースが選択されていません)。私は接続ファイルを持っています。
<?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
mysql_select_db()の最後に 'またはdie(mysql_error());'を追加しましたが、何も変更されませんでした。私の 'require_once( 'connections/conn1.php');には、ホスト名、データベース、ユーザ名、パスワードとともにmy mysql_connect()コードが含まれていますが、私も' die(mysql_error()); ' mysql_connectの終わりです。私の$ _POST変数が空であるということは、 'print_r($ _POST); //画面に" Array() "という行を表示したときです。 '画面に出力されるのは 'Array() 'これは、すべての投稿変数の配列を出力する必要があります。 –
これはフォームが送信される前のものではなく、この場合mysql_select_db()は呼び出されません。設定されている$ _POST ['login']インデックスに依存します。したがって、$ _POST配列が空でない場合 –