title: Getting an integer from MySql using php
body: <p>I am quite new to php and I have some problems with my final year project at school. I have an issue retrieving an integer from a Select statement using php.
  I have 2 tables:</p>
  
  <p>Table Camping :</p>
  
  <pre><code>capacity(int 11)
  spot_nb (int 11)
  location (varchar 20)
  availability (varchar 1) //this can be 'Y' or 'N'
  </code></pre>
  
  <p>Table reservation :</p>
  
  <pre><code>reservation_nb (int 10 auto_increment)
  spot_nb (int 11)
  uin (varchar 8; null)
  persons_nb (int 5)
  price (int 11)
  email (varchar 60)
  </code></pre>
  
  <p>And for php I have the following code:</p>
  
  <pre><code>$query5 = $conn-&gt;prepare("SELECT MAX(spot_nb) from camping where capacity=2 and availability='Y'");
  $query5-&gt;execute();
  $result = $query5-&gt;fetch(PDO::FETCH_ASSOC);
  $id = (int) $result;
  </code></pre>
  
  <p>to get the max value from table camping and insert into reservation with this code</p>
  
  <pre><code>$query6 = $conn-&gt;prepare("INSERT INTO reservation (price, persons_nb, email, spot_nb) VALUES (:price, 2, :email, :id);");
  $query6-&gt; bindParam(':price', $campingNumber);
  $query6-&gt; bindParam(':email', $email);
  $query6-&gt; bindParam(':id', $id);
  </code></pre>
  
  <p>But every time query6 is executed, the spot_nb that is inserted is 1.</p>
  
  <p>Thank you,
  Alex.</p>