PHP MYSQLi:实现头位置调用未定义的函数redirect()

时间:2016-03-23 15:34:01

标签: php

嗨,大家好我已经工作了一段时间,现在将代码从MySQL重写为MySQLi,但在此之前没问题,现在需要重定向问题(标题:位置,所以我希望有人可以帮助解决此代码中的最后一件事

我得到了错误

  

致命错误:调用未定义的函数redirect()   第62行/home/lafanke1/public_html/link/includes/submit.php

尝试运行标头位置时: 代码是这样的: 如果没有登录则不执行以下代码转到最后并重定向到登录中名为(../index.php)的登录页面然后如果submit1然后执行以下代码为submit1,如果不是submit2在那里当其中一个被执行时执行转到../ admin / index.php

希望你能帮忙!

 <?php
 session_start(); error_reporting(E_ALL);
 require('connection.php'); 

    if(!isset($_SESSION['id'])) {
        $username = $_SESSION['username'];
        $userId = $_SESSION['id'];

    } else {




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






mysqli_query($dbCon, "UPDATE infor SET isCount = isCount + 1 WHERE isCount=(SELECT min(isCount) FROM (SELECT * FROM infor) b) LIMIT 1") or die(mysqli_error());
    mysqli_query($dbCon, "UPDATE members SET isMcount = isMcount + 1 WHERE username = '".$username."' ") or die(mysqli_error());

    $_SESSION['success'] = 'Page Updated';


} else {
        //get the rest of the pages
        $sql = mysqli_query($dbCon, "SELECT * FROM infor WHERE isCount=(select min(isCount) from infor) LIMIT 1");
        while ($row = mysqli_fetch_object($sql)){
        $pageforum = $row->pageForum;
        $pagess = $row->pageTitle;
        $mlink = $row->imgLink;
        $pageforum = mysqli_real_escape_string($dbCon, $pageforum); 
        $pagess  = mysqli_real_escape_string($dbCon, $pagess);
        $mlink  = mysqli_real_escape_string($dbCon, $mlink);    
        }

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

    $username = $_POST['username'];


    $user = mysqli_real_escape_string($dbCon, $username);
    $keywords = $_SESSION['varname'];
    mysqli_query($dbCon, "UPDATE infor SET isCount = isCount + 1 WHERE isCount=(SELECT min(isCount) FROM (SELECT * FROM infor) b) LIMIT 1") or die(mysqli_error());
    mysqli_query($dbCon, "UPDATE members SET isMcount = isMcount + 1 WHERE username = '".$username."' ") or die(mysqli_error());

    mysqli_query($dbCon, "INSERT INTO pending (usernA,pageT,pageF,imgL,keyW) VALUES ('$username','$pagess','$pageforum','$mlink','$keywords')")or die(mysqli_error());
    $_SESSION['success'] = 'Pending Added';


} 

} 
}
?>
<?php

  // if submit1 or submit 2 then go here
              if(isset($_POST['submit1']) || isset($_POST['submit2']) ) { 
                            redirect('../admin/index.php'); 
              } else {
    if(!isset($_SESSION['id'])) {
        $username = $_SESSION['username'];
        $userId = $_SESSION['id'];

   // if not log in then go here
        header('Location: ../index.php');
        die();
        // if not log in then go here
    } 
}}

?>

2 个答案:

答案 0 :(得分:0)

重定向不存在于原生let url = NSURLComponents() url.scheme = "http" url.host = "localhost" var path : NSString = "/" path = path.stringByAppendingPathComponent("entitylist") path = path.stringByAppendingPathComponent("foo") path = path.stringByAppendingPathComponent("entity") path = path.stringByAppendingPathComponent("bar") url.path = path as String url.URL // http://localhost/entitylist/foo/entity/bar 中,在PHP这样的框架中。

您应该使用它来重定向:

  

标题(&#39;位置:../ admin / index.php&#39;);   出口;

详情请参阅:http://php.net/manual/en/function.header.php

答案 1 :(得分:-2)

redirect函数不作为php函数存在。请改用header('Location: ...'),就像在文件末尾一样。

此外,删除文件中间的关闭和打开php标记。它将注册为输出并阻止您更改HTTP标头。

您的代码可能更像这样:

<?php
session_start(); error_reporting(E_ALL);
require('connection.php'); 

if(!isset($_SESSION['id'])) {
    $username = $_SESSION['username'];
    $userId = $_SESSION['id'];

} else {

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

        mysqli_query($dbCon, "UPDATE infor SET isCount = isCount + 1 WHERE isCount=(SELECT min(isCount) FROM (SELECT * FROM infor) b) LIMIT 1") or die(mysqli_error());
            mysqli_query($dbCon, "UPDATE members SET isMcount = isMcount + 1 WHERE username = '".$username."' ") or die(mysqli_error());

            $_SESSION['success'] = 'Page Updated';

    } else {
            //get the rest of the pages
            $sql = mysqli_query($dbCon, "SELECT * FROM infor WHERE isCount=(select min(isCount) from infor) LIMIT 1");
            while ($row = mysqli_fetch_object($sql)){
            $pageforum = $row->pageForum;
            $pagess = $row->pageTitle;
            $mlink = $row->imgLink;
            $pageforum = mysqli_real_escape_string($dbCon, $pageforum); 
            $pagess  = mysqli_real_escape_string($dbCon, $pagess);
            $mlink  = mysqli_real_escape_string($dbCon, $mlink);    
            }

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

            $username = $_POST['username'];


            $user = mysqli_real_escape_string($dbCon, $username);
            $keywords = $_SESSION['varname'];
            mysqli_query($dbCon, "UPDATE infor SET isCount = isCount + 1 WHERE isCount=(SELECT min(isCount) FROM (SELECT * FROM infor) b) LIMIT 1") or die(mysqli_error());
            mysqli_query($dbCon, "UPDATE members SET isMcount = isMcount + 1 WHERE username = '".$username."' ") or die(mysqli_error());

            mysqli_query($dbCon, "INSERT INTO pending (usernA,pageT,pageF,imgL,keyW) VALUES ('$username','$pagess','$pageforum','$mlink','$keywords')")or die(mysqli_error());
            $_SESSION['success'] = 'Pending Added';


        } 

    } 
}
//
//Code edited below
//

// if submit1 or submit 2 then go here
if(isset($_POST['submit1']) || isset($_POST['submit2']) ) { 
    header('Location: ../admin/index.php');
    exit();
} else {
    if(!isset($_SESSION['id'])) {
        $username = $_SESSION['username'];
        $userId = $_SESSION['id'];

   // if not log in then go here
        header('Location: ../index.php');
        exit();
        // if not log in then go here
    } 
}