I am currently working on a project but can't continue due a error that keeps on coming and I don't know why but perhaps you guys would know. When I fill in my form and want to insert my data in the database I get the error feedback account creation failed. Which is below.
so here is the code:
// write new users data into database
$sql = "INSERT INTO users (user_name, user_password_hash, user_email, user_creation_timestamp, user_activation_hash, user_provider_type, user_persnaam, user_bondsnummer, user_telefoonnummer, user_leeftijd, user_enkelsterkte, user_dubbelsterkte, user_geslacht)
VALUES (:user_name, :user_password_hash, :user_email, :user_creation_timestamp, :user_activation_hash, :user_provider_type, :user_persnaam, :user_bondsnummer, :user_telefoonnummer, :user_leeftijd, :user_dubbelsterkte, :user_enkelsterkte, :user_geslacht)";
$query = $this->db->prepare($sql);
$query->execute(array(':user_name' => $user_name,
':user_password_hash' => $user_password_hash,
':user_email' => $user_email,
':user_persnaam' => $user_persnaam,
':user_bondsnummer' => $user_bondsnummer,
":user_telefoonnummer" => $user_telefoonnummer,
":user_enkelsterkte" => $user_enkelsterkte,
":user_dubbelsterkte" => $user_dubbelsterkte,
":user_leeftijd" => $user_leeftijd,
':user_geslacht' => $user_geslacht,
':user_creation_timestamp' => $user_creation_timestamp,
':user_activation_hash' => $user_activation_hash,
':user_provider_type' => 'DEFAULT'));
$count = $query->rowCount();
if ($count != 1) {
$_SESSION["feedback_negative"][] = FEEDBACK_ACCOUNT_CREATION_FAILED;
return false;
}
the problem seems to be that I can't write anything into my database but I am sure that I can connect and update everything but not write. So the problem isn't with the connection to the database. I think it has something to do with the rowcount but maybe you guys know what's wrong. The double quotes aren't the problem I've checked that already.
Thanks in advance
I don't know if this will be helpful, @fred
gave you a few clue, and you said you are sure the connection is good. Here is what I caught:
INSERT INTO users
(user_name,
user_password_hash,
user_email,
user_creation_timestamp,
user_activation_hash,
user_provider_type,
user_persnaam,
user_bondsnummer,
user_telefoonnummer,
user_leeftijd,
user_enkelsterkte, /* here user_enkelsterkte is first */
user_dubbelsterkte, /* here user_dubbelsterkte is second */
user_geslacht)
VALUES (:user_name,
:user_password_hash,
:user_email,
:user_creation_timestamp,
:user_activation_hash,
:user_provider_type,
:user_persnaam,
:user_bondsnummer,
:user_telefoonnummer,
:user_leeftijd,
:user_dubbelsterkte, /* here user_dubbelsterkte is first */
:user_enkelsterkte, /* here user_enkelsterkte is second */
:user_geslacht)
If there is a column type or length mismatch it will fail.
Here is a better way to write your code would be:
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($query = $this->db->prepare($sql)) {
// put code here
}else{
echo "
PDO::errorInfo():
";
print_r($this->db->errorInfo());
}
You can do error checking on connection, prepare()
or execute()
.
Now you should find out if you get an error.