Code PHP et HTML imbriqués dans une page PHP
magritte78
Messages postés
11
Statut
Membre
-
soft1ne -
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.
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.
A voir également:
- Code PHP et HTML imbriqués dans une page PHP
- Code ascii - Guide
- Supprimer une page dans word - Guide
- Code puk bloqué - Guide
- Comment déverrouiller un téléphone quand on a oublié le code - Guide
- Code activation windows 10 - Guide
13 réponses
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
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
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>";
}
} ?>
...
<?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>";
}
} ?>
Remplace le bout de code correspondant, par celui la, je pense que ca devrait fonctionner !
Donne des nouvelles
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>";
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.
...
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.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
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>";
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.";}
...
...
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.";}
...
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.
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.
non non cette syntaxe est bonne,
mais si tu fait ca ca marche pas ??
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.";}