I'm new to mySQL, and the code I used, which was working, is apparently out of date, so I switched to PDO. I tried to transfer my coding as accurately as possible from the old style to PDO, but now I can't connect and I'm sure I'm just doing something silly to mess it up.
Here's my old code which worked:
//insert.php
mysql_connect("localhost","root","root");//database connection
mysql_select_db("Menu_Items");
$name = $_POST['food'];
$order = "INSERT INTO foods
(name)
VALUES
('$name')";
//inserting data order
//declare in the order variable
$result = mysql_query($order);
if($result){
echo("<br>Input data is succeed");
}else{
echo("<br>Input data is fail");
}
Here's my new PDO code which is not working:
$dbc = "mysql:host=localhost;dbname=Menu_Items";
$user = "root";
$pass = "root";
$pdo = new pdo($dbc, $user, $pass);
$name = $_POST['food'];
$insert = "INSERT INTO foods (name) VALUES ('$name')";
$result = pdo -> query($insert);
if($result){
echo("<br>Input data is succeed");
}else{
echo("<br>Input data is fail");
}
Where's the problem at? Thanks.