I've been looking around a bit on different ways of inserting data into a database table, and I am not sure which one is the right/best/most secure way of doing it.
I have a form input in which a user can enter some data. I have the variables:
$name = "Steve";
, $password = "abc123";
, $ip = "1.1.1.1";
and $admin = 0;
The way I currently insert this data into the table is as following:
$q = "INSERT INTO users (username, password, ip, admin) VALUES ('$name', '$password', '$ip', '$admin')";
$query = $db->prepare($q);
$result = $query->execute();
What improvements would you make? And why? I've seen a few put :name
instead of $name
. But when I did that, it literally inserted ":name" into the database, and not the actual name of the person.