al_alb
al_alb

Reputation: 39

PDO prepared statement with insertion in database

Please i have this quetion, I have here:

$query = $db->prepare('Update survey_content  set '.$type.' = '.$type.'+1  where id = '.$where);
$query->execute();

I'm new to PDO and i really don't know how to create a new query, i need to add a record on the database, is it ok like this?

$query1 = $db->prepare('INSERT INTO daily (selected)
VALUES (.$type.)');
$query1->execute();

Upvotes: 0

Views: 35

Answers (1)

juergen d
juergen d

Reputation: 204746

Use a placeholder and fill the value in the execute method

$query1 = $db->prepare("INSERT INTO daily (selected)
                        VALUES (?)");
$query1->execute($selected_data);

or bind the parameter seperately

$query1 = $db->prepare("INSERT INTO daily (selected)
                        VALUES (:sel_dat)");
$query1->bindParam(":sel_dat",$selected_data);
$query1->execute();

Upvotes: 1

Related Questions