title: Inserting numeric data in mySQL database using PDO (PHP)
body: <p>I'm trying to insert string (:make and :model) and numeric (:year and :mileage) data in MySQL database using PHP Data Objects (PDO). The problem is that code doesn't insert the numeric data in the DB (I guess the reason is in the code which automaticaly changes the :year and :mileage datatype from int to str. 'year' and 'mileage' columns in the DB table are INT type.) How can I change my code to insert :year and :mileage as INT data?</p>
  <pre><code>//PDO
  &lt;?php
  $pdo = new PDO('mysql:host=localhost;port=8888;dbname=xxxx', 
     'xxx', 'xxx');
  $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
   //SQL 
   $sql = &quot;INSERT INTO autos (make, model, year, mileage)
                    VALUES (:make, :model, :year, :mileage)&quot;;
          $stmt = $pdo-&gt;prepare($sql);
          $stmt-&gt;execute(array(
              ':make' =&gt; $_POST['make'],
              ':model' =&gt; $_POST['model'],
              ':year' =&gt; $_POST['year'],
              ':mileage' =&gt; $_POST['mileage']));
          $_SESSION['success'] = 'Record Added';
          header( 'Location: index.php' ) ;
          return;
  ?&gt;
  
  &lt;form method=&quot;post&quot;&gt;
  &lt;p&gt;Make:
  &lt;input type=&quot;text&quot; name=&quot;make&quot;&gt;&lt;/p&gt;
  &lt;p&gt;Model:
  &lt;input type=&quot;text&quot; name=&quot;model&quot;&gt;&lt;/p&gt;
  &lt;p&gt;Year:
  &lt;input type=&quot;number&quot; name=&quot;year&quot;&gt;&lt;/p&gt;
  &lt;p&gt;Mileage:
  &lt;input type=&quot;number&quot; name=&quot;mileage&quot;&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Add New&quot;/&gt;
  
  &lt;!--SQL schema--!&gt;
  CREATE TABLE autos (
    autos_id INTEGER NOT NULL KEY AUTO_INCREMENT,
    make VARCHAR(255),
    model VARCHAR(255),
    year INTEGER,
    mileage INTEGER
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>