sinesine sinesine - 1 year ago 100
PHP Question

PHP MySQL Insert - Syntax Error: unexpected 'try' (T_TRY)

I have a basic form and code that inserts the data into my database, however I'm getting a syntax error at line 6, where it says

try {


// config for db and pdo connection variables
include 'pdo_config.php'

try {
// new pdo connection
$conn = new PDO($dsn, $user, $pass, $opt);

// prepare statement and bind parameters
$stmt = $conn->prepare("INSERT INTO tbl_example (first_name, last_name, email)
VALUES (:first_name, :last_name, :email)");

$stmt->bindParam(':first_name', $first_name);
$stmt->bindParam(':last_name', $last_name);
$stmt->bindParam(':email', $email);

// post data
$first_name = $_POST['first_name']
$last_name = $_POST['last_name']
$email = $_POST['email']

// execute statement

// success or error message
echo "New record created successfully";
catch(PDOException $e)
echo "Error: " . $e->getMessage();

$conn = null;


Answer Source

include a ;

include 'pdo_config.php';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download