[MySQL & PHP]Ecrire dans un base de donné
nor67290
Messages postés
395
Date d'inscription
Statut
Membre
Dernière intervention
-
nor67290 Messages postés 395 Date d'inscription Statut Membre Dernière intervention -
nor67290 Messages postés 395 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je n'arrive pas a faire fonctionner se code Merci
Norman FELTZ
<center><p>Ajouter votre adresse dans la BDD !</p></center> <center><strong>Votre E-mail :</strong><input type="text" name="mail"/></center><br/> <center><input type="submit" name="send" value="Ajouter Mail"/></center> <?php if(isset($_POST['send'])) { $mail = $_POST['mail']; try { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options); }catch(Exception $e) { die('Erreur : '.$e->getMessage()); } $bdd=query('INSERT INTO 'testphp'('mail') VALUES (''.$mail.'')'); echo 'L\'adresse '.$mail.' a ete ajoute !'; } ?>
Je n'arrive pas a faire fonctionner se code Merci
Norman FELTZ
A voir également:
- [MySQL & PHP]Ecrire dans un base de donné
- Base de registre - Guide
- Ecrire en gras sur whatsapp - Guide
- Comment écrire # sur pc - Guide
- Écrire en majuscule - Guide
- Formules mathématiques de base - Télécharger - Études & Formations
2 réponses
Si tu veux qu'on t'aide essai de nous aider aussi en nous donnant le maximum d'information et non pas en nous balançant ton code.
Essai comme ça:
$bdd=query("INSERT INTO testphp (mail) VALUES ('".$mail."')");
As-tu une erreur qui s'affiche?
Quel est le comportement de ton code après validation?
Essai comme ça:
$bdd=query("INSERT INTO testphp (mail) VALUES ('".$mail."')");
As-tu une erreur qui s'affiche?
Quel est le comportement de ton code après validation?
Salut !
Tu as oublier la balise <form>, qui doit englober tout les champs de ton formulaire !
Et auss, t'as oublier d'échaper des quotes !
Tu as oublier la balise <form>, qui doit englober tout les champs de ton formulaire !
Et auss, t'as oublier d'échaper des quotes !
<form method="POST" action="#"> <center> <p>Ajouter votre adresse dans la BDD !</p> </center> <center> <strong>Votre E-mail :</strong> <input type="text" name="mail"/> </center> <br/> <center> <input type="submit" name="send" value="Ajouter Mail"/> </center> </form> <?php if(isset($_POST['send'])) { $mail = $_POST['mail']; try { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options); } catch(Exception $e) { die('Erreur : '.$e->getMessage()); } $bdd=query('INSERT INTO testphp(mail) VALUES ('.$mail.')'); echo 'L\'adresse '.$mail.' a ete ajoute !'; } ?>
Marche pas
( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.fr)' at line 1' in C:\wamp\www\email.php on line 29
( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.fr)' at line 1 in C:\wamp\www\email.php on line 29
( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.fr)' at line 1' in C:\wamp\www\email.php on line 29
( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.fr)' at line 1 in C:\wamp\www\email.php on line 29
Merci mais mtn c'est cette page qui ne marche pas !
<?php
try {
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', 'n.f67290');
$reponse = $bdd->query('SELECT mail FROM testphp');
while($donnees = $reponse->fetch())
{
$donnees['mail'] = $to;
$subject = 'Test Script Norman';
$message = '
<html>
<head>
<title>Calendrier des anniversaires pour Août</title>
</head>
<body>
<p>Le test du mail !</p>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to.'' . "\r\n";
$headers .= 'From: <contact@oxocraft.ch>' . "\r\n";
if(mail($to, $subject, $message, $headers))
{
echo 'Les mail ont ete envoye';
}
else
{
echo 'Les mail n\'ont pas pu etre envoye';
}
}
$reponse->closeCursor();
}catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
<?php
try {
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', 'n.f67290');
$reponse = $bdd->query('SELECT mail FROM testphp');
while($donnees = $reponse->fetch())
{
$donnees['mail'] = $to;
$subject = 'Test Script Norman';
$message = '
<html>
<head>
<title>Calendrier des anniversaires pour Août</title>
</head>
<body>
<p>Le test du mail !</p>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to.'' . "\r\n";
$headers .= 'From: <contact@oxocraft.ch>' . "\r\n";
if(mail($to, $subject, $message, $headers))
{
echo 'Les mail ont ete envoye';
}
else
{
echo 'Les mail n\'ont pas pu etre envoye';
}
}
$reponse->closeCursor();
}catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>