Code PHP et HTML imbriqués dans une page PHP

magritte78 Messages postés 11 Statut Membre -  
 soft1ne -
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. soft1ne
     
    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
    0
  2. magritte78 Messages postés 11 Statut Membre
     
    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>";
    }

    } ?>
    0
  3. soft1ne
     
    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>";  
    
    
    
    0
    1. soft1ne
       
      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 !!
      0
    2. soft1ne
       
      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
      0
  4. magritte78 Messages postés 11 Statut Membre
     
    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.
    0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. soft1ne
     
    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>";  
    0
  7. magritte78 Messages postés 11 Statut Membre
     
    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.";}

    ...
    0
    1. magritte78 Messages postés 11 Statut Membre
       
      A cette place, rien ne s'affiche
      0
  8. soft1ne
     
    Tu as bien coller le pavé que je t'ai donnée ???
    Je viens de tester et chez moi tout marche !!!!
    0
  9. magritte78 Messages postés 11 Statut Membre
     
    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.
    0
  10. soft1ne
     
    Alors remplace ton print par un :

    $temp.="


    ca devrait fonctionner et arriver par mail !
    0
  11. magritte78 Messages postés 11 Statut Membre
     
    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.
    0
  12. soft1ne
     
    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.";}  
    0
  13. magritte78 Messages postés 11 Statut Membre
     
    Super soft1ne, tu es mon sauveur, ça marche.
    Merci encore de m'avoir consacré de ton temps.
    0
  14. soft1ne
     
    Pfiou on y est arrivé ;-)

    pas de probleme, bonne soirée tout de meme,
    Cordialement
    Soft1ne
    0