Pas d'erreur et pourtant la base est vide

Résolu
Utilisateur anonyme -  
 Utilisateur anonyme -
Salut !
Je me remets au PHP MySQL. Il y a du changement en MySQL depuis 2008.

Pour commencer mysql_* est apparemment aux oubliettes. Alors j'ai cherché du code pour savoir comment insérer des données. Pas simple !

Voici mon code :
$Connexion=Mysqli_Connect("localhost", "root", "","u178618735_cours");
If (Mysqli_Connect_Errno())
{
Die("Echec de connexion : ".Mysqli_Connect_Error());
}
Mysqli_Query($Connexion, "INSERT INTO participants (ID, Nom, Password) VALUES ('', $Nom, $PWD)");
Mysqli_Close($Connexion);

Les variables sont "Ok" il y a bien une valeur mais lorsque je regarde dans PHP My Admin, il n'y a rien. Pourtant, je n'ai pas d'erreur.
Ou sont passés les données ?
Par ailleurs, comment tester si Mysqli_Query a bien fait son travail ? Merci

1 réponse

Utilisateur anonyme
 
Voici la Structure...
0
BloodyAngel Messages postés 1482 Date d'inscription   Statut Contributeur Dernière intervention   403
 
Hello,

je constate que SessionID est non-null, mais dans ta requête tu ne lui attribues pas de valeur...
0
Utilisateur anonyme
 
Bonjour !
L'erreur n'est pas là car j'ai corrigé dans la table maintenant "Null" et je l'ai ajouté dans la commande. Pareil
Mysqli_Query($Connexion, "INSERT INTO participants (ID, Nom, Password, SessionID) VALUES ('', $Nom, $PWD,'')");
0
BloodyAngel Messages postés 1482 Date d'inscription   Statut Contributeur Dernière intervention   403
 
Sorry mais je ne vois pas trop...
En fait j'utilise plutôt PDO. Ca fonctionne très bien et c'est plus sécurisé.
Voici un exemple :

function connectDB() {
try {
$dsn = 'mysql:host=localhost;dbname=Nom_Base_de_donnees';
$dbh = new PDO($dsn, 'login_mysql', 'mot_de_passe', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch (PDOException $e)
{
$dbh = FALSE;
}
return $dbh;
}

// strSQL = Requête SQL
function selectDB($strSQL){
$dbh = connectDB();
if($dbh === FALSE) {
return FALSE;
}
else {
try {
$sth = $dbh->query($strSQL);
if ($sth === FALSE)
{
return FALSE;
}
else {
$result = $sth->fetchAll(PDO::FETCH_BOTH);
return $result;
}
}
catch(Exception $e) {
return FALSE;
}
}
}

function updateDB($strSQL){
$dbh = connectDB();
if($dbh == FALSE) {
return FALSE;
}
else {
try {
$requete = $dbh->exec($strSQL);
return $requete;
}
catch (Exception $e) {
return FALSE;
}
}
}


Sais pas si ça peut t'aider.
0
BloodyAngel Messages postés 1482 Date d'inscription   Statut Contributeur Dernière intervention   403
 
Bizarre mais j'arrive plus à lire toute une partie de ce qu'on a écrit.
0
Utilisateur anonyme > BloodyAngel Messages postés 1482 Date d'inscription   Statut Contributeur Dernière intervention  
 
Ca doit modérer sec !
0