The first example will add data to mysql database without any issue. The second block of code - where I try to use variables wont. Can someone please explain where I am going wrong?
<?php
$query = "INSERT INTO subjects (menu_name,position,visible) VALUES ('Edit me',4,1)";
$result = mysqli_query($connection, $query);
Problem CODE:
<?php
$menu_name = "TEST";
$position = 5;
$visible = 1;
$query = "INSERT INTO subjects (menu_name,position,visible)
VALUES ('{menu_name}',{position}, {visible})";
$result = mysqli_query($connection, $query);
$" on every single var inside the brackets.{menu_name}should be{$menu_name}and so on, despite you should first PREPARE the string before quering it. Parsing variables directly in the query is dangerous. read more: php.net/manual/en/pdo.prepared-statements.php (BIND parameters)