php - Insert a unix_timestamp into a mysql database -


i'm trying create function in php can save unix_timestamp mysql database keep getting error message invalid parameter numbers.

this code function:

function addnew($array){ $sql = 'insert user (id, acronym, name, password)  values (?, ?, ?, unix_timestamp());';    $id  = isset($_post['id'])  ? $_post['id'] : null; $acronym   = isset($_post['acronym'])   ? $_post['acronym'] : null(); $name   = isset($_post['name'])   ? strip_tags($_post['name']) : null; $password    = isset($_post['password'])    ? strip_tags($_post['password']) : null;  $params = array($id, $acronym, $name, $password); $res=$this->db->executequery($sql, $array);  if($res) { $output = 'användare skapad!'; } else { $output = 'användare kunde tyvärr ej skapas.<br>'; } return $output; } 

this code user input:

$cont = new cuseradmin($db);  $id  = isset($_post['id'])  ? $_post['id'] : null; $acronym   = isset($_post['acronym']) ? strip_tags($_post['acronym']) : null; $name   = isset($_post['name']) ? strip_tags($_post['name']) : null; $password   = isset($_post['password']) ? strip_tags($_post['password']) : null;  $save = isset($_post['save'])  ? true : false;  $output = null; if($save){ $array = array($id, $acronym, $name, $salt ); $output = $cont->addnew($array); }   // , store in variables in belio container. $belio['title'] = "ny användare";  $belio['main'] = <<<eod <h1>skapa ny användare</h1> <form method=post> <div class="freebox"> <p><label>acronym <br> <input type='text' name='acronym'/> </label></p> <p><label>name:<br> <input type='text' name='name'/> </label></p> <p><label>password:<br> <input type='password' name='salt' /> </label></p> </div> <p><input type='submit' name='save' value='spara'/></p> <p>{$output}</p> </form> eod; 

the code not work however, error message:

warning: pdostatement::execute(): sqlstate[hy093]: invalid parameter number: number of bound variables >does not match number of tokens in /home/saxon/students/20141/josj14/www/webflix/belio/src/cdatabase /cdatabase.php on line 121

the problem seems unix_timestamp itself, when exchange '?' information saved database.

is possible save unix timestamp databse way?

$sql = 'insert user (id, acronym, name, password)  values (?, ?, ?, unix_timestamp());'; 

here insert timestamp password field

array($id, $acronym, $name, $password); 

here enter variable, $password non-existant parameter.

$sql = 'insert user (id, acronym, name, password, date_created)  values (?, ?, ?, ?, unix_timestamp());'; 

would work, change date_created appropriate field name of course

also should hash passwords, storing plaintext bad practice


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -