mysql_select_db() 导致我的 $_POST 变量变空
当我使用 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>
When I use mysql_select_db() my $_POST variables come up empty, if I comment it out then my $_POST variables are fine but my queries can execute. (no database selected). I do have my connection file included.
Here is the breakdown of my code:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 mysql_select_db($database_conn1, $conn1) 放入 conn1.php 文件中。
Put mysql_select_db($database_conn1, $conn1) inside your conn1.php file.
我遇到了几乎同样的问题...在这里查找“通过 $_POST-值发送数据库名称不起作用”。
我用 if (isset($_POST['dbName'])) {php-code} 包围我的 php 代码,它工作了:) 这花了我大约 8 个小时!我希望这会帮助某人!
I had nearly the same problem... Look up "Send database-name by $_POST-value not work" here.
I surround my hole php-code with if (isset($_POST['dbName'])) {php-code} and it works :) It takes me about 8 hours! I hope this will hely someone!