Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial



I am new to PHP and MYSQL, I am trying to do a simple insert into db but not able to can some one help. code below.

I am using the same db what i got from the study material

The error is.

Parse error: syntax error, unexpected 'INTO' (T_STRING) in C:\xampp\htdocs\basicform.php on line 29

PHP code

try{ $db = new PDO("mysql:host=localhost;dbname=shirts4mike","root",""); $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $db->exec("SET NAMES 'utf8'");

catch(Exception $e){
    echo "Could not connect to the database.";

    INSERT INTO `products` (`sku`, `name`, `img`, `price`, `paypal`) VALUES(101, 'Logo Shirt, Red', 'img/shirts/shirt-101.jpg', 18.00, '9P7DLECFD4LKE');

}catch(Exception $e){
    echo "No No NO";

2 Answers

You can't just execute a MySQL query in PHP, you need to send the query as a string through an API, presumably through the PDO instance $db you declared earlier. Something like $db->query("INSERT INTO...") might be what you are looking for.

Thank you John.