Home > OS >  ERROR: localhost redirected you too many times USING PHP
ERROR: localhost redirected you too many times USING PHP

Time:06-13

Good morning, I'm a beginner in PHP. I'm developing an evaluation system for teacher and I have encountered this problem.

This page isn’t working localhost redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

MY CODE:

<?php 

////DATABASE CONNECTION HERE! session_start();

include("connection.php");
include("functions.php");
    
    
    //CHECKING THE BUTTON IF IS IT CLICK!
    
        if(isset($_POST['submit'])){
            if(!empty(['submit'])){
                if(!empty(['statement'])){
                    
                    $statement1 = $_POST['statement1'];
                    $statement2 = $_POST['statement2'];
                    $statement3 = $_POST['statement3'];
                    $statement4 = $_POST['statement4'];
                    $statement5 = $_POST['statement5'];
                    $statement6 = $_POST['statement6'];
                    
                    $result=mysqli_query($mysqli, "INSERT INTO results VALUES('','$statement1', '$statement2', '$statement3', '$statement4', '$statement5', '$statement6')");
    
                    if($result){
                        echo'<script type="text/javascript"> alert("YOUR RESPONSE HAS BEEN SUBMITTED. THANK YOU!") </script>';
                        
                    }
                }
                else{ 
                    echo'<script type="text/javascript"> alert("SUBMIT YOUR RESPONSE") </script>';
                    }
            }       
            else{
                echo'<script type="text/javascript"> alert(" PLEASE CLICK ONE RADIO BUTTON PER QUESTIONS! </script>';
                }
        }   
    header("Location: evaluation.php");
    die;
                                    

?>

CodePudding user response:

Your problem is header("Location: evaluation.php");. You're inadvertently redirecting to yourself, infinitely.

Remove that statement.

TYPICAL ("CORRECT") BEHAVIOR:

  1. User browses to your first page, e.g. "index.php".
  2. You might do a database lookup to generate some HTML, or it might be static HTML.
  3. In any case, the page contains an HTML form, and has a "Submit" button.
  4. The user fills in the form, and clicks the button.
  5. This calls your NEXT PHP page.
  6. And so on...

It sounds like maybe you want your "first page" to query the database and present a list of teachers. Specifically, PHP will 1) query the database, 2) generate an HTML form, 3) which containins an HTML table, 4) one row per teacher.

The user selects a teacher (e.g. by clicking a radio button for the teacher on that row), and clicks "submit".

The "second page" might be an "evaluation form" for the chosen teacher. The user clicks "submit" on the second form when he's completed the evaluation.

The "third" (and final) PHP page might be an HTML message that says "Thank you for submitting this evaluation".

No "redirects". Just series of HTML forms, generated one at a time.

CodePudding user response:

  • header() function returns error like ERR_TOO_MANY_REDIRECTS that change page name.php to some url like below.
header("Location: /index.php"); 

Or

header("Location: ./index.php"); 

Or

header("Location: ../application/index.php"); 
  •  Tags:  
  • php
  • Related