在if条件后PHP echo不工作
我不知道出了什么问题,但有以下几点 “如果”条件后,echo不工作。有人能告诉我如何解决这个问题吗在if条件后PHP echo不工作,php,Php,我不知道出了什么问题,但有以下几点 “如果”条件后,echo不工作。有人能告诉我如何解决这个问题吗 $select_query = mysql_query(some query); $fetch_pass = mysql_fetch_array($select_query); $getpass = $fetch_pass['field_value']; echo $getpass; //Here it is working if($_POST['userp
$select_query = mysql_query(some query);
$fetch_pass = mysql_fetch_array($select_query);
$getpass = $fetch_pass['field_value'];
echo $getpass; //Here it is working
if($_POST['userpass'] == $getpass)
{
echo $getpass; // Here it is working
$select_storename = mysql_query("Some Query");
$fetch_storename = mysql_fetch_array($select_storename);
$getstorename = $fetch_storename['field_value'];
echo $getpass; // Here if $getstorename has output then getpass is working else it is not working
$select_brandname = mysql_query("Some Query"); // This query is never executing
$fetch_brandname = mysql_fetch_array($select_brandname); // This is never working
$getbrandname = $fetch_brandname['field_value']; // This is never working
echo $gettime; // Here it is not working
// None of these if conditions are working.
if($getstorename != null) {
header("location:http://localhost/stores/");
}
if($getbrandname != null) {
header("location:http://localhost/brands/");
}
}
其概念是$select\u query
将获取密码,在第一个“if”条件下,我们检查密码是否正确,然后有两个查询$select\u storename
和$select\u brandname
,只有第一个查询有效。如果我将订单更改为$select_brandname
为first,则只有它工作,第一个查询工作,第二个查询不工作,“If”条件也不工作
更新1
我认为这是由于查询失败造成的,如何忽略并绕过失败的查询?您的代码存在以下问题:
- 不测试的返回值。查询可能会失败
- 不测试的返回值。查询可能成功,并返回0行
- 标题前的输出。必须在脚本生成任何输出之前调用,除非已启用输出缓冲。(依赖输出缓冲不是一种稳健的设计。)
$select_query = mysql_query(some query);
if (!$select_query) {
/* Query failed. Display error page. */
exit;
}
$fetch_pass = mysql_fetch_array($select_query);
if (!count ($fetch_pass)) {
/* Password incorrect. Display error page. */
exit;
}
$getpass = $fetch_pass['field_value'];
mysql_free_result ($fetch_pass);
if($_POST['userpass'] !== $getpass) {
/* Password incorrect. Display error page. */
exit;
}
$getstorename = null;
$getbrandname = null;
$select_storename = mysql_query ("Some Query");
if ($select_storename) {
$fetch_storename = mysql_fetch_array ($select_storename);
if (count ($fetch_storename)) {
$getstorename = $fetch_storename['field_value'];
}
mysql_free_result ($select_storename);
}
$select_brandname = mysql_query ("Some Query");
if ($select_brandname) {
$fetch_brandname = mysql_fetch_array ($select_brandname);
if (count ($fetch_brandname)) {
$getbrandname = $fetch_brandname['field_value'];
}
mysql_free_result ($select_brandname);
}
if ($getstorename != null) {
header("location:http://localhost/stores/");
} else if ($getbrandname != null) {
header ("location:http://localhost/brands/");
} else {
/* None found. Display error page or some default page. */
}
关于代码的一些注释:
- 代码使用了一些人觉得不舒服的提前退出。另一种方法是使用复杂的
阶梯if…else
- 代码在显示错误页后退出。如果这是在函数中,则返回可能更合适
- 如果您创建单独的错误页并将它们放在适当的位置,那么代码可以变得更容易阅读
- 在我看来,当您处理完数据库资源时,您应该始终调用它,即使PHP随后会清理掉。如果没有别的,它倾向于鼓励您编写更干净的代码
- 和,您不应以明文形式存储密码。使用或类似工具加密密码,并仅存储和比较加密的密码。有关更多信息,请参阅
如果条件不是真的
试着打开wp\u调试,看看是否有其他错误。ini\u set('display\u errors',1);错误报告(E_全部)代码>并让我们知道是否有任何错误?是否绕过失败的查询?为什么要提供SQL已损坏的应用程序?如果查询失败,请修复查询问题。使用$select\u query=mysql\u query(一些查询)或die(mysql\u error())
查看失败的原因。不应该提供md5作为加密选项,它是多余的,因为周围有很多彩虹表,在你的哈希计算出来之前需要一段时间,但答案仍然很好+1:)@Darren:是的,md5()
这些天非常糟糕。稍后我将编辑我的答案。谢谢