Code PHP et HTML imbriqués dans une page PHP

Bonjour,

Voici un code que j'essaie de faire fonctionner mais ma syntaxe n'est certainement pas très rigoureuse :
...
<td colspan=\"2\">
if($_POST["choix"] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST["adresse1"]." ".$_POST["adresse2"]."<br>".$_POST["code_postal"]." ".$_POST["ville"]." ; } else {print "Je viendrai chercher la commande, téléphonez-moi";}
</td>

...

La page PHP refuse de s'ouvrir dans le navigateur.

Merci de votre aide.

13 réponses

  1. Pfiou on y est arrivé ;-)

    pas de probleme, bonne soirée tout de meme,
    Cordialement
    Soft1ne
    1. Super soft1ne, tu es mon sauveur, ça marche.
      Merci encore de m'avoir consacré de ton temps.
      1. non non cette syntaxe est bonne,

        mais si tu fait ca ca marche pas ??

        if($_POST['choix'] == '1') { $temp.= "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST['adresse1']." ".$_POST['adresse2']."<br>".$_POST['code_postal']." ".$_POST['ville'] ; } else {$temp.= "Je viendrai chercher la commande, téléphonez-moi.";}  
        1. Non, ça ne marche pas. Tout tourne autour de ce if($POST['choix']... qui n'est pas dans la variable $temp. Si j'essaie de l'intégrer dedans, ça plante le fichier PHP. Je crois que c'est ma syntaxe qui est nase.
          1. Alors remplace ton print par un :

            $temp.="


            ca devrait fonctionner et arriver par mail !
            1. C'est à dire que la fonction commençant par if($POST['choix']....., n'est pas dans la variable $temp mais à l'extérieur, elle est donc traitée, je vois le résultat s'afficher 1 secondes sur une page blanche dans mon navigateur mais rien dans le mail envoyer par sendmail.
              1. Tu as bien coller le pavé que je t'ai donnée ???
                Je viens de tester et chez moi tout marche !!!!
                1. Désolé, ça ne fonctionne pas. Je veux dire que le fichier n'engendre pas d'erreur, le PHP fait son boulot sauf pour la ligne :
                  ...
                  if($_POST['choix'] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST['adresse1']." ".$_POST['adresse2']."<br>".$_POST['code_postal']." ".$_POST['ville'] ; } else {print "Je viendrai chercher la commande, téléphonez-moi.";}

                  ...
                  1. A cette place, rien ne s'affiche
                2. oui ok, donc fait ce que j'ai dit, tu remplace le code correspondant par ceci :

                  // Récupère les éléments du formulaire  
                  $temp="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>  
                  <body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">  
                  <center>  
                  <table width=\"820\" border=\"0\">  
                  <div align=\"justify\">  
                  <TR>  
                  <TD width=\"220\"> </TD>  
                  <TD width=\"600\"><br><br><div align=\"right\"><h1 class=\"rouge\">  
                  Commande passée par le site Internet</h1></TD>  
                  </TR>  
                  <tr>  
                  <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Contact</h1></td>  
                  </tr>  
                  <tr>  
                  <td> Nom</td>  
                  <td>  ".ucfirst( strtolower($_POST["nom"]))."</td>  
                  </tr>  
                  <tr>  
                  <td> Prénom</td>  
                  <td>  ".ucfirst( strtolower($_POST["prenom"]))."</td>  
                  </tr>  
                  <tr>  
                  <td> Email </td>  
                  <td>  ".$_POST["email"]."</td>  
                  </tr>  
                  <tr>  
                  <td> Téléphone</td>  
                  <td>  ".wordwrap(($_POST["telephone"]), 2, ' ', 1)."</td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\">  </td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Commande</h1></td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\"> ".$_POST["commande0"]."</td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\"> ".$_POST["commande1"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande2"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande3"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande4"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande5"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande6"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande7"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande8"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande9"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande10"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande11"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande12"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande13"]."</td>  
                  </tr><tr>  
                  <td colspan=\"2\"> ".$_POST["commande14"]."</td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\">  </td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Livraison</h1></td>  
                  </tr>  
                  <tr>  
                  <td colspan=\"2\"> "; 
                  if($_POST['choix'] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST['adresse1']." ".$_POST['adresse2']."<br>".$_POST['code_postal']." ".$_POST['ville'] ; } else {print "Je viendrai chercher la commande, téléphonez-moi.";}  
                  $temp .= " 
                  </td>  
                  </tr>  
                  
                  </div>  
                  </table>  
                  </center></body></html>";  
                  1. Merci pour ton aide mais le pb vient de la ligne :
                    ...
                    if($_POST["choix"] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST["adresse1"]." ".$_POST["adresse2"]."<br>".$_POST["code_postal"]." ".$_POST["ville"]." ; } else {print "Je viendrai chercher la commande, téléphonez-moi.";}

                    ...
                    car quand je l'enlève du fichier, ça marche très bien.
                    1. Remplace le bout de code correspondant, par celui la, je pense que ca devrait fonctionner !

                      Donne des nouvelles

                      
                      
                      // Récupère les éléments du formulaire  
                      $temp="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>  
                      <body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">  
                      <center>  
                      <table width=\"820\" border=\"0\">  
                      <div align=\"justify\">  
                      <TR>  
                      <TD width=\"220\"> </TD>  
                      <TD width=\"600\"><br><br><div align=\"right\"><h1 class=\"rouge\">  
                      Commande passée par le site Internet</h1></TD>  
                      </TR>  
                      <tr>  
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Contact</h1></td>  
                      </tr>  
                      <tr>  
                      <td> Nom</td>  
                      <td>  ".ucfirst( strtolower($_POST["nom"]))."</td>  
                      </tr>  
                      <tr>  
                      <td> Prénom</td>  
                      <td>  ".ucfirst( strtolower($_POST["prenom"]))."</td>  
                      </tr>  
                      <tr>  
                      <td> Email </td>  
                      <td>  ".$_POST["email"]."</td>  
                      </tr>  
                      <tr>  
                      <td> Téléphone</td>  
                      <td>  ".wordwrap(($_POST["telephone"]), 2, ' ', 1)."</td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\">  </td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Commande</h1></td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\"> ".$_POST["commande0"]."</td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\"> ".$_POST["commande1"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande2"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande3"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande4"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande5"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande6"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande7"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande8"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande9"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande10"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande11"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande12"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande13"]."</td>  
                      </tr><tr>  
                      <td colspan=\"2\"> ".$_POST["commande14"]."</td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\">  </td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Livraison</h1></td>  
                      </tr>  
                      <tr>  
                      <td colspan=\"2\"> "; 
                      if($_POST["choix"] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST["adresse1"]." ".$_POST["adresse2"]."<br>".$_POST["code_postal"]." ".$_POST["ville"] ; } else {print "Je viendrai chercher la commande, téléphonez-moi.";}  
                      $temp .= " 
                      </td>  
                      </tr>  
                      
                      </div>  
                      </table>  
                      </center></body></html>";  
                      
                      
                      
                      1. J'ai oublié, fait un
                         print $temp;
                        a la fin fin de ton fichier !!

                        C'est pour cela que tu n'a rien d'affiché entre autre !!
                      2. je viens de modifier j'avais fait une erreur, le code devrait etre ok la, je ne l'ai pas testé alors donne moi des nouvelles
                    2. Merci d'avance soft1ne pour ton aide. Voici la page PHP en son entier :
                      ...

                      <?php // Script pour envoi de formulaire
                      // Interface PHP pour mail()
                      function sendMail($mFrom,$mTo,$sujet,$body) {
                      //le destinataire
                      $mTo = "contact@tequila.com";
                      // l'émetteur
                      $mFrom = $_POST["email"];
                      $mail = $_POST["email"];
                      $nom = $_POST["nom"];
                      $prenom = $_POST["prenom"];
                      $livraison = $_POST["choix"];

                      $tete = "From: ".$mFrom."\n";
                      $tete .= "Content-type:text/html\n";
                      $tete .= "Reply-To: ".$mFrom."\n";
                      // et zou... false si erreur d'émission
                      return mail($mTo,$sujet,$body,$tete);
                      }

                      // Si le champ email est renseigné
                      if($_POST["email"]) {

                      // Récupère les éléments du formulaire
                      $temp="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>
                      <body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
                      <center>
                      <table width=\"820\" border=\"0\">
                      <div align=\"justify\">
                      <TR>
                      <TD width=\"220\"> </TD>
                      <TD width=\"600\"><br><br><div align=\"right\"><h1 class=\"rouge\">
                      Commande passée par le site Internet</h1></TD>
                      </TR>
                      <tr>
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Contact</h1></td>
                      </tr>
                      <tr>
                      <td> Nom</td>
                      <td>  ".ucfirst( strtolower($_POST["nom"]))."</td>
                      </tr>
                      <tr>
                      <td> Prénom</td>
                      <td>  ".ucfirst( strtolower($_POST["prenom"]))."</td>
                      </tr>
                      <tr>
                      <td> Email </td>
                      <td>  ".$_POST["email"]."</td>
                      </tr>
                      <tr>
                      <td> Téléphone</td>
                      <td>  ".wordwrap(($_POST["telephone"]), 2, ' ', 1)."</td>
                      </tr>
                      <tr>
                      <td colspan=\"2\">  </td>
                      </tr>
                      <tr>
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Commande</h1></td>
                      </tr>
                      <tr>
                      <td colspan=\"2\"> ".$_POST["commande0"]."</td>
                      </tr>
                      <tr>
                      <td colspan=\"2\"> ".$_POST["commande1"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande2"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande3"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande4"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande5"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande6"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande7"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande8"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande9"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande10"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande11"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande12"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande13"]."</td>
                      </tr><tr>
                      <td colspan=\"2\"> ".$_POST["commande14"]."</td>
                      </tr>
                      <tr>
                      <td colspan=\"2\">  </td>
                      </tr>
                      <tr>
                      <td colspan=\"2\" class=\"pointilles\">   <h1 class=\"rouge\">Livraison</h1></td>
                      </tr>
                      <tr>
                      <td colspan=\"2\">
                      if($_POST["choix"] == '1') { print "Merci de me contacter pour une livraison à l\'adresse ci-dessous :<br>".$_POST["adresse1"]." ".$_POST["adresse2"]."<br>".$_POST["code_postal"]." ".$_POST["ville"]." ; } else {print "Je viendrai chercher la commande, téléphonez-moi.";}
                      </td>
                      </tr>

                      </div>
                      </table>
                      </center></body></html>";

                      // Caractères spéciaux
                      $temp = stripslashes($temp);

                      // Envoie le message
                      if(sendmail($mFrom,$mTo,"Commande envoyée par ".ucfirst( strtolower($_POST["prenom"]))." ".ucfirst( strtolower($_POST["nom"]))." ",$temp)) {
                      $URL = "confirmation_order.php?n=$nom&p=$prenom&l=".($_POST["choix"])." ";
                      print "<script language=\"JavaScript\">location.replace('$URL');</script>";
                      } else {
                      // ou un message d'erreur
                      echo "<font color=red>Impossible d'envoyer le formulaire. Veuillez réessayer.</font>";
                      }

                      } ?>
                      1. Salut tu devrais nous coller ta page complete car la il y a un truc qui va pas :

                        ceci : <td colspan=\"2\"> tu l'a dans un print ???
                        Car ca voudrait dire que ta condition est ausssi dan un print, donc donne nous un peu plus d'info et je t'aiderais !

                        Bonne soirée