0

Can anybody explain to me why my insert function in MySQL is not inserting data into the database? There are no errors/warnings but my data is not successfully inserting.

function add_update_visitor_information() {
    include 'config.php';

    var_dump($conn);

    $stmt = $conn->prepare(
        "INSERT INTO visitor_contacts (
            'salutation_dr/mr/ms', 
            first_name, 
            middle_init, 
            last_name, 
            suffix, 
            email
        ) VALUES (
            :salutation, 
            :firstname, 
            :middleinitial, 
            :lastname, 
            :suffix, 
            :email
        )"
    );

    echo '<br><br>'.$_POST['salutation'].'<br>';
    echo $_POST['firstname'].'<br>';
    echo $_POST['middleinitial'].'<br>';
    echo $_POST['lastname'].'<br>';
    echo $_POST['suffix'].'<br>';
    echo $_POST['email'].'<br><br>';

    $stmt->execute(array(
        ':salutation' => $_POST['salutation'],
        ':firstname' => $_POST['firstname'],
        ':middleinitial' => $_POST['middleinitial'],
        ':lastname' => $_POST['lastname'],
        ':suffix' => $_POST['suffix'],
        ':email' => $_POST['email']
    ));

    var_dump($stmt);

    echo '<br><br>Adding or Updating!';
}

Here is my output:

object(PDO)#1 (0) { } 

test
yo
yo
yo
test
test@test.com

object(PDOStatement)#2 (1) { ["queryString"]=> string(180) "INSERT INTO visitor_contacts ('salutation_dr/mr/ms', first_name, middle_init, last_name, suffix, email) VALUES (:salutation, :firstname, :middleinitial, :lastname, :suffix, :email)" } 

Adding or Updating!

I'm pretty confused!

Geoffrey
  • 5,407
  • 10
  • 43
  • 78
  • 5
    Pretty sure `'salutation_dr/mr/ms'` should be ``salutation_dr/mr/ms`` (back ticks not quotes). Also make sure your pdo object is set to throw exceptions when it errors. – bassxzero Jul 29 '16 at 17:42
  • `ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)` Escape that title column (or rename it) with backticks, not quotes.. http://dev.mysql.com/doc/refman/5.7/en/identifiers.html – chris85 Jul 29 '16 at 17:43
  • @bassxzero, if you make an answer I will accept it. –  Jul 29 '16 at 17:53

2 Answers2

0

Pretty sure 'salutation_dr/mr/ms' should be `salutation_dr/mr/ms` (back ticks not quotes). Also make sure your pdo object is set to throw exceptions when it errors.

bassxzero
  • 4,838
  • 22
  • 34
0

using salutation_dr/mr/ms as column name is not suggested but if you want to use this as column name you can try using back ticks ` in your query

Vijay Dohare
  • 731
  • 5
  • 22