I'm trying to learn how to write a PDO insert statement, so apologise if the code is not so good, It's coming up with error:
SQLSTATE[42000]: Syntax error or access violation: 1064 at line 3
But I can't see why it's not working.
Note: I'm trying to pass html input data to a database, and in prepared statement online it says something like this:
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$variable is relating to the database field name, but how do you reference the name in the html input field?
code can be found here and below: http://pastebin.com/fjAy1Fvn
<?php
include_once 'dbconnect.php';
if(isset($_POST["update_vacancies"])){
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// begin the transaction
$conn->beginTransaction();
// our SQL statements
$conn->exec("INSERT INTO vacancies (vac_id, vac_post_date, vac_job_title, vac_comp_name, vac_ess_one, vac_ess_two, vac_ess_three, vac_ess_four, vac_ess_five, vac_ess_six, vac_ess_seven, vac_ess_eight, vac_ess_nine, vac_ess_ten, vac_des_one, vac_des_two, vac_des_three, vac_des_four, vac_des_five, vac_des_six, vac_des_seven, vac_des_eight, vac_des_nine, vac_des_ten, add_info)
VALUES ('vacData', 'postaDate', 'jobTitle', 'companyNanme', 'vac_ess_one', 'vac_ess_two', 'vac_ess_three', 'vac_ess_four', 'vac_ess_five', 'vac_ess_six', 'vac_ess_seven', 'vac_ess_eight', 'vac_ess_nine', 'vac_ess_ten', ,'vac_des_one' ,'vac_des_two' ,'vac_des_three' ,'vac_des_four' ,'vac_des_five' ,'vac_des_six' ,'vac_des_seven' ,'vac_des_eight' ,'vac_des_nine' ,'vac_des_ten' ,'add_info' )");
// commit the transaction
$conn->commit();
echo "New vacancy created successfully";
}
catch(PDOException $e)
{
// roll back the transaction if something failed
$conn->rollback();
echo "Error: " . $e->getMessage();
}
}
$conn = null;
?>
Any help is genuinely appreciated.