我不知道怎么了,但以下内容。
在“如果”条件之后,回声不起作用。谁能告诉我如何解决此问题?
$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_query
将获取密码,在第一个“ if”条件下,我们检查密码是否正确,然后有2个查询$select_storename
和$select_brandname
,只有第一个是工作。如果我先将顺序从$select_brandname
更改为只有它有效,则第一个查询有效,第二个查询无效,并且“ if”条件也无法正常工作。
更新1
我认为这是由于查询失败导致的,我如何忽略并绕过失败的查询?
您的代码有以下问题:
mysql_query()
的返回值。查询可能会失败。mysql_query()
的返回值。查询可能成功,并返回0行。mysql_fetch_array()
称为before,除非打开了输出缓冲,否则脚本将产生任何输出。 (并且依赖于输出缓冲不是一个可靠的设计。)还请注意,不建议使用MySQL扩展(并且可能无法维护)。您应该使用mysql_fetch_array()
或header()
。
您的代码应如下所示:[[something:
header()
有关代码的一些注释:
$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
或类似方法对密码进行加密,并仅存储和比较加密的密码。有关更多信息,请参见require()
。