I am trying to insert some datas in DB with the following function (I don't get any errors but datas don't get added in my DB)
File name=insertuserdb:
<?php
function insertUser($U,$P,$E)
{
$conn = connPDO();//*function to connect to my DB on the other file
$query = ("INSERT INTO user (Username, Password, Email) VALUES (:User,:Pass,:Email)");
$conn_prepare = $conn->prepare($query);
$conn_prepare->execute(array( "User" => $U,"Pass" => $P,"Email" =>$E ));
$id = $conn->lastInsertId();
$conn_prepare->closeCursor();
return $id;
}
?>
AND (my connection function (works/sorry for french)) file name=dbc3.php:
<?php
function connPDO()
{
$PARAM_hote='localhost'; // le chemin vers le serveur
$PARAM_port='';
$PARAM_nom_bd='mygcpage'; // le nom de votre base de données
$PARAM_utilisateur='root'; // nom d'utilisateur pour se connecter
$PARAM_mot_passe=''; // mot de passe de l'utilisateur pour se connecter
try {
$connexion = new PDO('mysql:host='.$PARAM_hote.';port='.$PARAM_port.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
return $connexion;
}
catch(Exception $e) {
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
die;
}
} $conn = connPDO(); if ($conn) { echo "connected"; } else { echo "ERROR: Could not connect!"; } ?>
finally (my form) file name=login.php:
<form method="POST" action="login.php">
<table id="reg">
<th>Please the fill in the following:</th>
<tr><!--Username -->
<td>
<p>Username:</p>
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
<p>Password:</p>
</td>
<td>
<input type="password" name="pass1" />
</td>
</tr>
<tr>
<td>
<p>Comfirm Password:</p>
</td>
<td>
<input type="password" name="pass2" />
</td>
</tr>
<tr>
<td>
<p>Email:</p>
</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="register" />
</td>
<td></td>
</tr>
</table>
</form>
Aucun commentaire:
Enregistrer un commentaire