Hi:
I am using this script to insert data from a Form into a Database. I am new to PHP and trying to learn. However, after 3 days of banging my head I still cannot make this script Insert data to my MySQL Database.
When I insert the First name and Last Name into the form and click Submit, I receive the following error:
Parse error: syntax error, unexpected $end in /home/www/DOMAIN/admin/insert.php on line 34
However, line #34 is about two lines after the PHP scrip has closed. Can someone tell me what I am doing wrong?
Here is My Form and my INSERT.PHP script I am using for my Form.
MY FORM:
[php]
A small example page to insert some data in to the MySQL database using PHP
Firstname:
Lastname:
My INSERT.PHP file:
<?php // Connection data (server_address, database, name, password) $hostdb = 'localhost'; $namedb = 'XXX_test'; $userdb = 'XXX_test'; $passdb = 'XXXXX'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // Define an insert query $sql = "INSERT INTO `nametable` (`fname`, `lname`) VALUES ('$_POST[fname]'), ('$_POST[lname]'); $count = $conn->exec($sql); } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; $conn = null; // Disconnect ?>[/php]