【发布时间】:2012-01-16 19:13:32
【问题描述】:
当我使用 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()设置吗?您是否尝试将die(mysql_error())添加到您的mysql_select_db()的末尾以确保它不会死? -
我在 mysql_select_db() 的末尾添加了
or die(mysql_error());,但没有任何改变。我的require_once('connections/conn1.php');包括代码我的mysql_connect()以及主机名、数据库、用户名和密码,我在mysql_connect的末尾还有一个or die(mysql_error());。我的 $_POST 变量为空的意思是,当我点击print_r ($_POST);//Outputs "Array()" to the screen行时,我看到的所有输出到屏幕都是Array(),当它应该输出我所有的帖子变量的数组时。 -
提交表单时会出现这种情况,而不是之前,在这种情况下不会调用 mysql_select_db(),因为它取决于 $_POST['login'] 索引设置,即提交表单时,因此当 $_POST 数组不为空时
-
提交表单后,
if(isset($_POST['Login']))这一行显示为 false,因此为了检查从我的表单传入的值是什么,我输入了print_r ($_POST);//Outputs "Array()" to the screen行,但它仍然显示为空提交表单后的数组。 -
错误,您没有发布任何标记为“登录”的值。这是一个按钮,但我不是真正的表单字段-我可能是错的,但我从未遇到过安装 Move the print_r($_POST);声明到文件的最顶部并检查结果;这样,任何错误代码都无法清空您的 $_POST 变量。
标签: php database database-connection