Rien ne s'envoie dans la BDD

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Rien ne s'envoie dans la BDD

Re: Rien ne s'envoie dans la BDD

par Ascla » 09 mars 2016, 13:38

Bonjour,
Il va falloir procéder par étape pour régler ton problème.
Tout d'abord, la condition est-elle respectée lors de l'envoie ?
Si celle ci l'est, il va falloir jeter un coup d'œil sur ton fichier log de php. Voici un guide pour y accéder : faq-tutoriels/page-blanche-script-php-c ... 73178.html

Je pense que ton soucis provient de ta connexion en bdd. Je t'encourage à utiliser le try pour en tirer les erreurs.
<?php
/* Connexion à une base ODBC avec l'invocation de pilote */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connexion échouée : ' . $e->getMessage();
}

?>

Rien ne s'envoie dans la BDD

par Sato » 09 mars 2016, 12:24

Bonjour,

Je développe un petit espace admin et je tombe sur un os, mon script m'a l'air correcte mais rien ne s'envoie...

Voici le code PHP:
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=#', '#', '#');

if(isset($_POST['forminscription'])) {
$societe = htmlspecialchars($_POST['societe']);
$nom = htmlspecialchars($_POST['nom']);
$prenom = htmlspecialchars($_POST['prenom']);
$adresse = htmlspecialchars($_POST['adresse']);
$pays = htmlspecialchars($_POST['pays']);
$codepostale = htmlspecialchars($_POST['codepostale']);
$ville = htmlspecialchars($_POST['ville']);
$siret = htmlspecialchars($_POST['siret']);
$tva = htmlspecialchars($_POST['tva']);
$mail = htmlspecialchars($_POST['mail']);
$telephone = htmlspecialchars($_POST['telephone']);
$mobile = htmlspecialchars($_POST['mobile']);
$fax = htmlspecialchars($_POST['fax']);
$ref = htmlspecialchars($_POST['ref']);
$infos = htmlspecialchars($_POST['infos']);
if(!empty($_POST['nom']) AND !empty($_POST['prenom']) AND !empty($_POST['adresse']) AND !empty($_POST['pays']) AND !empty($_POST['codepostale']) AND !empty($_POST['ville']) AND !empty($_POST['mail']) AND !empty($_POST['ref'])) {
$insertmbr = $bdd->prepare("INSERT INTO clients (societe, nom, prenom, adresse, pays, codepostale, ville, siret, tva, mail, telephone, mobile, fax, ref, infos) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$insertmbr->execute(array($societe, $nom, $prenom, $adresse, $pays, $codepostale, $ville, $siret, $tva, $mail, $telephone, $mobile, $fax, $ref, $infos));
$erreur = "Client crée avec succés";
} else {
$erreur = "Merci de remplir les champs obligatoires";
}
}
?>
<html>
<head>
<title>Nouveau client</title>
<meta charset="utf-8">
</head>
<body>
<div align="center">
<h2>Insertion</h2>
<br /><br />
<form method="POST" action="">
<table>
<tr>
<td align="right">
<label for="societe">Societe :</label>
</td>
<td>
<input type="text" placeholder="Societe" id="societe" name="societe" value="<?php if(isset($societe)) { echo $societe; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="nom">Nom :</label>
</td>
<td>
<input type="text" placeholder="Nom" id="nom" name="nom" value="<?php if(isset($nom)) { echo $nom; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="prenom">Prénom :</label>
</td>
<td>
<input type="text" placeholder="Prénom" id="prenom" name="prenom" value="<?php if(isset($prenom)) { echo $prenom; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="adresse">Adresse:</label>
</td>
<td>
<textarea id="adresse" name="adresse" rows="4" cols="50"></textarea>
</td>
</tr>
<tr>
<td align="right">
<label for="pays">Pays:</label>
</td>
<td>
<input type="text" placeholder="Pays" id="pays" name="pays" value="<?php if(isset($pays)) { echo $pays; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="codepostale">Code postale:</label>
</td>
<td>
<input type="text" placeholder="Code Postale" id="codepostale" name="codepostale" value="<?php if(isset($codepostale)) { echo $codepostale; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="ville">Ville:</label>
</td>
<td>
<input type="text" placeholder="Ville" id="ville" name="ville" value="<?php if(isset($ville)) { echo $ville; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="siret">SIRET:</label>
</td>
<td>
<input type="text" placeholder="SIRET" id="siret" name="siret" value="<?php if(isset($siret)) { echo $siret; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="tva">TVA:</label>
</td>
<td>
<input type="text" placeholder="tva" id="tva" name="tva" value="<?php if(isset($tva)) { echo $tva; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="mail">Mail :</label>
</td>
<td>
<input type="email" placeholder="Mail" id="mail" name="mail" value="<?php if(isset($mail)) { echo $mail; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="telephone">Telephone fixe :</label>
</td>
<td>
<input type="text" placeholder="Telephone" id="telephone" name="telephone" value="<?php if(isset($telephone)) { echo $telephone; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="mobile">Telephone portable :</label>
</td>
<td>
<input type="text" placeholder="Portable" id="mobile" name="mobile" value="<?php if(isset($mobile)) { echo $mobile; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="fax">Fax :</label>
</td>
<td>
<input type="text" placeholder="Fax" id="fax" name="fax" value="<?php if(isset($fax)) { echo $fax; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="ref">Reference client :</label>
</td>
<td>
<input type="text" placeholder="Référence client" id="ref" name="ref" value="<?php if(isset($ref)) { echo $ref; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="infos">Infos diverses :</label>
</td>
<td>
<textarea id="infos" name="infos" rows="4" cols="50"></textarea>
</td>
</tr>
<tr>
<td></td>
<td align="center">
<br />
<input type="submit" name="forminscription" value="Valider" />
</td>
</tr>
</table>
</form>
<?php
if(isset($erreur)) {
echo '<font color="red">'.$erreur."</font>";
}
?>
</div>
</body>
</html>
Si quelqu'un peut m'aiguiller...

Thomas.