如何使用PHP修复本地主机中的“ ERR_TOO_MANY_REDIRECTS”

时间:2018-12-30 09:38:30

标签: php localhost

每次打开php文件时,都会出现一条消息

  

”此页面无法正常运行localhost重定向了您太多次。   尝试清除您的cookie。   ERR_TOO_MANY_REDIRECTS“

也许与标题的位置以及所有其他原因有关,但我似乎无法找到导致此问题的错误。

我检查了所有查询和php代码几次,但我一定忽略了某些东西,否则我不知道如何解决它。

 <?php 
  function console_log( $data ){
    echo '<script>';
    echo 'alert('. json_encode( $data ) .')';
    echo '</script>';
  }

  include("includes/dbh.inc.php");
  if(isset($_GET['user_email']) && !empty($_GET['user_email'])){

    $event_id=$_GET['event_id'];
    $query = "SELECT * FROM user_details WHERE user_email = '$user_email'";
    $statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $number_of_rows = $statement->rowCount();

    foreach($result as $row){
      $email = $row["user_email"];
      $name = $row["username"];
      $profpic = $row["user_profile"];
      $phone = $row["phone_no"];
      $address = $row["user_address"];
      $events = $row["events_no"];
      $company = $row["company_name"];
      $companyloc = $row["company_location"];

    }
  }else{
    header("Location: edit-profile.php");
  }

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

       include("includes/dbh.inc.php");

       // get values form input text and number

       // $id = $_POST['id'];
       $email = $_POST['email'];
       $name = $_POST['name'];
       $profpic = $_FILES['logo']['name'];
       $phone = $_POST['phone'];
       $address = $_POST['address'];
       $events = $_POST['events'];
       $company = $_POST['company'];
       $companyloc = $_POST['companyloc'];

       // mysql query to Update data
       $query = "UPDATE `user_details` SET `user_email`='".$email."',`username`='".$name."',`user_profile`='".$profpic."',`phone_no`='".$phone_no."',`user_address`='".$address."',`company_name`='".$company."',`company_location`='".$companyloc."' WHERE user_email =".$email."";

        if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) {
            $msg = "Image uploaded successfully";
          }else{
            $msg = "Failed to upload image";
          }

       $result = mysqli_query($connect, $query);

       if($result)
       {
           echo 'Data Updated';
       }else{
           echo 'Data Not Updated';
       }
       mysqli_close($connect);
    }
  ?>

预期的输出应显示此页面的UI布局,并且可以进行一些编辑,但直接错误过多出现

代码如下:

<body>
 <?php 
  function console_log( $data ){
    echo '<script>';
    echo 'alert('. json_encode( $data ) .')';
    echo '</script>';
  }

  include("includes/dbh.inc.php");
  if(isset($_GET['user_email']) && !empty($_GET['user_email'])){

    $event_id=$_GET['event_id'];
    $query = "SELECT * FROM user_details WHERE user_email = '$user_email'";
    $statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $number_of_rows = $statement->rowCount();

    foreach($result as $row){
      $email = $row["user_email"];
      $name = $row["username"];
      $profpic = $row["user_profile"];
      $phone = $row["phone_no"];
      $address = $row["user_address"];
      $events = $row["events_no"];
      $company = $row["company_name"];
      $companyloc = $row["company_location"];

    }
  }else{
    header("Location: edit-profile.php");
  }

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

       include("includes/dbh.inc.php");

       // get values form input text and number

       // $id = $_POST['id'];
       $email = $_POST['email'];
       $name = $_POST['name'];
       $profpic = $_FILES['logo']['name'];
       $phone = $_POST['phone'];
       $address = $_POST['address'];
       $events = $_POST['events'];
       $company = $_POST['company'];
       $companyloc = $_POST['companyloc'];

       // mysql query to Update data
       $query = "UPDATE `user_details` SET `user_email`='".$email."',`username`='".$name."',`user_profile`='".$profpic."',`phone_no`='".$phone_no."',`user_address`='".$address."',`company_name`='".$company."',`company_location`='".$companyloc."' WHERE user_email =".$email."";

        if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) {
            $msg = "Image uploaded successfully";
          }else{
            $msg = "Failed to upload image";
          }

       $result = mysqli_query($connect, $query);

       if($result)
       {
           echo 'Data Updated';
       }else{
           echo 'Data Not Updated';
       }
       mysqli_close($connect);
    }
?>

 <div class="wrapper">
    <div class="page-header page-header-xs" data-parallax="true" style="background-image: url('assets/img/fabio-mangione.jpg');">
        <div class="filter"></div>
    </div>
    <div class="section profile-content">
        <div class="container">
           <div class="tim-title text-center " >
              <h2 style="font-size: 3em;">Edit Profile Details</h2>
           </div>
            <div class="container-fluid" style="margin-left: 120px;">
                    <div class="form">
                        <form method="post" enctype="multipart/form-data" action="eventus-addevent.php">

                           <div class="container" style="margin-top: 50px;">
                            <div class="row">
                                <div class="col-sm-3">
                                    <label><h3>Profile Picture</h3></label>

                                </div>
                                <div class="col-sm-4" style="margin-left: 90px;">
                                    <div class="input-group" >
                                        <img name="pp"src="<?php echo images/$user_profile?>" alt="Circle Image" class="img-circle img-no-padding img-responsive">
                                    </div>
                                    <div>
                                        <input type="file" name="logo" >
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>
                            </div>

                            <div class="row">
                                <div class="col-sm">
                                    <label><h3>Profile name</h3></label>

                                </div>
                                <div class="col-sm-4">
                                    <div class="mui-textfield" style="margin-top: 25px;">
                                        <input type="text" name="title1" placeholder="Enter Event name here" value="<?php echo $title1;?>">
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>

                            </div>
                            <div class="row">
                                <div class="col-sm">
                                    <label><h3>Company Address</h3></label>

                                </div>
                                <div class="col-sm-4">
                                    <div class="mui-textfield" style="margin-top: 25px;">
                                        <input type="text" name="title1" placeholder="Enter Event name here" value="<?php echo $title1;?>">
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>

                            </div>
                            <div class="row">
                                <div class="col-sm">
                                    <label><h3>My Address</h3></label>

                                </div>
                                <div class="col-sm-4">
                                    <div class="mui-textfield" style="margin-top: 25px;">
                                        <input type="text" name="title1" placeholder="Enter Event name here" value="<?php echo $title1;?>">
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>

                            </div>
                             <div class="row">
                                <div class="col-sm">
                                    <label><h3>Contact Number</h3></label>

                                </div>
                                <div class="col-sm-4">
                                    <div class="mui-textfield" style="margin-top: 25px;">
                                        <input type="text" name="title1" placeholder="Enter Event name here" value="<?php echo $title1;?>">
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>

                            </div>
                             <div class="row">
                                <div class="col-sm">
                                    <label><h3>Email Adress</h3></label>

                                </div>
                                <div class="col-sm-4">
                                    <div class="mui-textfield" style="margin-top: 25px;">
                                        <input type="text" name="title1" placeholder="Enter Event name here" value="<?php echo $title1;?>">
                                    </div>
                                </div>
                                <div class="col-sm">

                                </div>

                            </div>
                             <br/><br/>

                            <div class="row">
                                <div class="col-sm-8">
                                    <button type="submit" name="update" class="btn btn-primary">SAVE EDIT</button>
                                </div>
                                <div class="col-sm-4">

                                </div>
                            </div>
                           <br/>

        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

  1. 不要重定向到同一页面。
  2. 使用标头后,只需添加die()或exit()。