An "insert into" mySQL query through PHP appears to work, but nothing is added -


edit: realized problem was trying insert $user_id, has string numbers" column user_id, type int. converted string integer. still didn't quite figure out errors though, that's because of time constraints. i'll other time.

i'm trying build website on top of advanced version of php login system provided @ http://www.php-login.net. in registration class of script, there's function adds new user database, , code works totally fine:

$query_new_user_insert = $this->db_connection->prepare('insert users (user_name, user_password_hash, user_email, user_activation_hash, user_registration_ip, user_registration_datetime) values(:user_name, :user_password_hash, :user_email, :user_activation_hash, :user_registration_ip, now())'); $query_new_user_insert->bindvalue(':user_name', $user_name, pdo::param_str); $query_new_user_insert->bindvalue(':user_password_hash', $user_password_hash, pdo::param_str); $query_new_user_insert->bindvalue(':user_email', $user_email, pdo::param_str); $query_new_user_insert->bindvalue(':user_activation_hash', $user_activation_hash, pdo::param_str); $query_new_user_insert->bindvalue(':user_registration_ip', $_server['remote_addr'], pdo::param_str); $query_new_user_insert->execute();  // id of new user             $user_id = $this->db_connection->lastinsertid();              if ($query_new_user_insert) {                 // send verification email                 if ($this->sendverificationemail($user_id, $user_email, $user_activation_hash)) {                     // when mail has been send                     $this->messages[] = $this->lang['verification mail sent'];                     $this->registration_successful = true;                 } else {                     // delete users account immediately, not send verification email                     $query_delete_user = $this->db_connection->prepare('delete users user_id=:user_id');                     $query_delete_user->bindvalue(':user_id', $user_id, pdo::param_int);                     $query_delete_user->execute();                      $this->errors[] = $this->lang['verification mail error'];                 }             } else {                 $this->errors[] = $this->lang['registration failed'];             } 

i tried copying code part of site using following code:

public function addnewtag($postcontent) {     if ($this->databaseconnection()) {         $query_add_tag = $this->db_connection->prepare('insert tags (tag_name, tag_short_name, tag_id, color, user_id, creation_time)  values(:tag_name, :tag_short_name, :tag_id, :color, :user_id, :creation_time)');         $query_add_tag->bindvalue(':tag_name', $postcontent['tag_name'], pdo::param_str);         $query_add_tag->bindvalue(':tag_short_name', $postcontent['tag_short_name'], pdo::param_str);         $query_add_tag->bindvalue(':tag_id', rand(100000000000, 999999999999), pdo::param_str);         $query_add_tag->bindvalue(':color', $postcontent['color'], pdo::param_str);         $query_add_tag->bindvalue(':user_id', $user_id, pdo::param_str);         $query_add_tag->bindvalue(':creation_time', time(), pdo::param_str);         $query_add_tag->execute();         if ($query_add_tag) {             return true;         } else {             return false;         }     } else {         return false;     } } 

the function called $_post variable $postcontent code

$content->addnewtag($_post); 

when so, function returns true ("1"), when check database content, nothing added. issue here? i'm not great mysql, maybe it's obvious error somewhere else in script.

are running in autocommit=0? if so, please set autocommit=1 or add commit @ end of function. should like:

$query_add_tag->commit(); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -