How to set multiple headers on the same PHP page?

Solved
fabi00 Posted messages 82 Status Member -  
fabi00 Posted messages 82 Status Member -
Hello,

Actually, I'm trying to create an express quote form with three modal windows on the same PHP page. Since I'm using multiple headers, I'm getting a little warning at compilation: Cannot modify header information - headers already sent. Is there a way to put multiple headers on the same page?

Thanks in advance ^^

I'm new, I don't know how this works, I'll try to send my code here...

<body> <a href="#demo1">Express Quote</a> <!--Form 1 --> <div id="demo1" class="modal1"> <div class="modal_content1"> <h1>Your quote request</h1> <p>Make your quote request in just a few clicks!</br></br></br></p> <h2>Your needs (Minimum total of 10 pieces)</h2> <form action="" method="post"> <p> <label for="modele">Model</label> <select name="modele" id="modele"/> <option>T-shirts</option> <option>Sweatshirts</option> <option>Jumpers</option> </select> <label for="quantite">Quantity</label> <input type="number" name="quantite" id="quantite" min="10" value="<?php if (isset($_POST['quantite'])){echo $_POST['quantite'];} ?>"/> <br></br> </p> <p> <label for="taille">Size</label> <select name="taille" id="taille"/> <option>XS</option> <option>S</option> <option>M</option> <option>L</option> <option>XL</option> </select> <label for="couleur">Color</label> <select name="couleur" id="couleur"> <option value="blue">blue</option> <option value="red">red</option> <option value="green">green</option> </select> </p> <p> <input type="submit" name="suivant" value="Next"/> </p> </form> <?php //If the "next" button is pressed if(isset($_POST['suivant'])){ //Retrieve the data from $_POST $modele=$_POST['modele']; $taille=$_POST['taille']; $couleur=$_POST['couleur']; $quantite=$_POST['quantite']; //Set session variables $_SESSION['modele'] = $modele; $_SESSION['taille'] = $taille; $_SESSION['couleur'] = $couleur; $_SESSION['quantite'] = $quantite; if($quantite == false){ echo "<h4>Please add a quantity</h4>"; } else{ // Go to form 2 header ('Location: #demo2'); die(); } } ?> <a href="#" class="modal_close1">×</a> </div> </div> <!--Form 2 --> <div id="demo2" class="modal2"> <div class="modal_content2"> <h1>Your quote request</h1> <p>Make your quote request in just a few clicks!</br></br></br></p> <h2>Additional information for printing</h2> <form action="" method="post"> <p> <label for="qualite">Quality</br></label> <select name="qualite" id="qualite"> <option>Promotional/1st price</option> <option>Best quality/price ratio</option> <option>High-end</option> </select> </p> <p> <label for="zone">Customization area</br></label> <select name="zone" id="zone"> <option>Heart</option> <option>Back</option> <option>Sleeve</option> </select> </p> <p> <label for="impression">Printing technique</br></label> <select name="impression" id="impression"> <option>DTG</option> <option>Quadri transfer</option> <option>Silkscreen</option> <option>Flex Flock</option> <option>Embroidery</option> <option>Sublimation</option> </select> </p> <p> <label for="fichier">Upload your files here</br></label> <input type="file" id="fichier" name="fichier" accept="image/png, image/jpeg, .ai, .eps, .pdf, .svg"> </p> <p> <input type="submit" name="retour1" value="Previous"/> <input type="submit" name="suivant1" value="Next"/> </p> </form> <?php //If the "next" button is pressed if(isset($_POST['suivant1'])){ //Retrieve the data from $_POST $qualite=$_POST['qualite']; $zone=$_POST['zone']; $impression=$_POST['impression']; $fichier=$_POST['fichier']; // Go to form 3 header('Location: #demo3'); die(); //header('Location: suite2.php'); //Set session variables $_SESSION['qualite'] = $qualite; $_SESSION['zone'] = $zone; $_SESSION['impression'] = $impression; $_SESSION['fichier'] = $fichier; } //If the "Previous" button is pressed if(isset($_POST['retour1'])){ // Go to form 1 header('Location: #demo1'); die(); } ?> <a href="#" class="modal_close2">×</a> </div> </div> </body>

1 answer

  1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
     
    Hello,

    It's not an issue with the "number" of headers... but an issue with the order of your code.
    The header instruction must not be located AFTER any output (whether it's HTML code or PHP echo statements)..

    In any case.. get into the habit of placing as much PHP code as possible BEFORE all your HTML code..
    Basically
     <?php //If the "next" button is pressed if(isset($_POST['suivant'])){ //We retrieve data from $_POST $modele=$_POST['modele']; $taille=$_POST['taille']; $couleur=$_POST['couleur']; $quantite=$_POST['quantite']; //We define session variables $_SESSION['modele'] = $modele; $_SESSION['taille'] = $taille; $_SESSION['couleur'] = $couleur; $_SESSION['quantite'] = $quantite; if($quantite == false){ echo "<h4>Please add a quantity</h4>"; } else{ // We go to form 2 header ('Location: #demo2'); die(); } } //If the "next" button is pressed if(isset($_POST['suivant1'])){ //We retrieve data from $_POST $qualite=$_POST['qualite']; $zone=$_POST['zone']; $impression=$_POST['impression']; $fichier=$_POST['fichier']; // We go to form 3 header('Location: #demo3'); die(); //header('Location: suite2.php'); //We define session variables $_SESSION['qualite'] = $qualite; $_SESSION['zone'] = $zone; $_SESSION['impression'] = $impression; $_SESSION['fichier'] = $fichier; } //If the "Previous" button is pressed if(isset($_POST['retour1'])){ // We go to form 1 header('Location: #demo1'); die(); } ?> <!Doctype html> <html> <head> <!-- your head code --> </head> <body> <a href="#demo1">Express Quote</a> <!--Form 1 --> <div id="demo1" class="modal1"> <div class="modal_content1"> <h1>Your quote request</h1> <p>Make your quote request in just a few clicks!</br></br></br></p> <h2>Your needs (Total of 10 pieces minimum)</h2> <form action="" method="post"> <p> <label for="modele">Model</label> <select name="modele" id="modele"/> <option>T-shirts</option> <option>Sweatshirts</option> <option>Pullovers</option> </select> <label for="quantite">Quantity</label> <input type="number" name="quantite" id="quantite" min="10" value="<?php if (isset($_POST['quantite'])){echo $_POST['quantite'];} ?>"/> <br></br> </p> <p> <label for="taille">Size</label> <select name="taille" id="taille"/> <option>XS</option> <option>S</option> <option>M</option> <option>L</option> <option>XL</option> </select> <label for="couleur">Color</label> <select name="couleur" id="couleur"> <option value="bleu">blue</option> <option value="rouge">red</option> <option value="vert">green</option> </select> </p> <p> <input type="submit" name="suivant" value="Next"/> </p> </form> <a href="#" class="modal_close1">×</a> </div> </div> <!--Form 2 --> <div id="demo2" class="modal2"> <div class="modal_content2"> <h1>Your quote request</h1> <p>Make your quote request in just a few clicks!</br></br></br></p> <h2>Additional information for printing</h2> <form action="" method="post"> <p> <label for="qualite">Quality</br></label> <select name="qualite" id="qualite"> <option>Promotional/1st price</option> <option>Best quality/price ratio</option> <option>High-end</option> </select> </p> <p> <label for="zone">Customization area</br></label> <select name="zone" id="zone"> <option>Heart</option> <option>Back</option> <option>Sleeve</option> </select> </p> <p> <label for="impression">Printing technique</br></label> <select name="impression" id="impression"> <option>DTG</option> <option>4-color transfer</option> <option>Screen printing</option> <option>Flex Flock</option> <option>Embroidery</option> <option>Sublimation</option> </select> </p> <p> <label for="fichier">Upload your files here</br></label> <input type="file" id="fichier" name="fichier" accept="image/png, image/jpeg, .ai, .eps, .pdf, .svg"> </p> <p> <input type="submit" name="retour1" value="Previous"/> <input type="submit" name="suivant1" value="Next"/> </p> </form> <a href="#" class="modal_close2">×</a> </div> </div> </body> </html> 


    --
    .
    Best regards,
    Jordane
    1
    1. fabi00 Posted messages 82 Status Member
       
      Hello,
      Great !! A big thank you to you, it works.
      0