Php mysql using NOW()

Hi… How do I accomplish what I’m failing at? I don’t know how to use the NOW() sql statement with the execute format below…

$query = “INSERT INTO notes SET admin_id=?,user_id=?,Note=?,created=?”;
$parameters = array($adminId,$user_id,$_POST[‘FormNotes’],NOW());
$statement = $db->prepare($query);
$error = ‘success’;
$errormsg = “Note added successfully”;

Are you using mysqli_* or PDO? It looks like you are using mysqli_* in your SQL statement, but then seem to be executing the bind placeholders in the ->execute line. This only works with PDO. So you really need to determine which database API you want to use. Then learn the correct way of inserting data into a database.

1 Like

NOW() is an SQL function and hence must be part of the statement to work. if you’ll pass it as data it’ll be a string without meaning.

1 Like

Good spot, it has no meaning within the PHP code where it is now.

The other thing would be to give the ‘created’ column a default value of current_timestamp and just not mention it in the query.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.