← CodePrimer
PHP
Intermediate
Database
PDO prepared INSERT
How do I insert a row safely?
Prepared INSERT.
<?php
$stmt = $pdo->prepare(
'INSERT INTO students (name, email) VALUES (?, ?)'
);
$stmt->execute([$name, $email]);
Notes
Never concatenate user input into SQL.
Keywords: insert · pdo · prepared · create
Related
PHP
Embed PHP inside HTML
How do I mix PHP and HTML?
SQL
CREATE DATABASE
How do I create a MySQL database?
PHP
PHP comments
How do I write comments in PHP?
SQL
ALTER TABLE add column
How do I add a column to an existing table?
PHP
PHP variable rules
What are the rules for PHP variables?
SQL
Foreign key relationship
How do I relate posts to users?