dtp19819 2016-01-11 18:43
浏览 6
已采纳

脚本标题的提前结束?

I have a problem with the code, it is the premature execution error when using header.

Code:

<?php
session_start();
require 'config.php';
$prepend = "<span class='welcome'>";
$append = "</span>";
if (!isset($_SESSION['name'])) {
header("Location: login.php");
}
echo $prepend."Здравей ".$_SESSION['name'].$append."</br>";


if (isset($_POST['submit'])) 
{

$newname = mysql_real_escape_string($_POST['newname']);
$newpass = mysql_real_escape_string($_POST['newpass']);
$oldpass = mysql_real_escape_string($_POST['oldpass']);
$checkPass = "SELECT pass from admin WHERE pass = '$_POST[oldpass]'";
$rs = mysqli_query($connect,$checkPass);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
if ($data > 0) 
{
        $query = "UPDATE admin SET pass ='".$_POST['newpass']."',name ='".$_POST['newname']."'" ;
        $result = mysqli_query($connect, $query);

    if ($result === true) 
    {
        echo "Update sucessfuly!";
    }

   }
    else {
    header('Location: admin.php?failed=1');
    }
 }
 ?>

The first time when you open the page the else part is performed immediately and I can not understand why.

  • 写回答

2条回答 默认 最新

  • douma5954 2016-01-11 19:09
    关注

    First you have 2 weird lines in your code:

    $rs = mysqli_query($connect,$checkPass);
    $data = mysqli_fetch_array($rs, MYSQLI_NUM);
    

    Those function don't exist, in fact you probably used the mysql_...() ones, as it seems confirmed by the previous statements.

    Now when you execute

    $data = mysql_fetch_array($rs, MYSQLI_NUM);
    

    then $data is an array (the next record returned) or FALSE (when no more record exist. And this statement should belong to a loop.

    Anyway, in the current form of your code, when you execute if ($data > 0), it can't return anything significative since $data is an array.

    So you must refactor all this piece of code according to your need (I guess you want to control that pass was really found by the previous query).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了