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:
Table Camping :
capacity(int 11)
spot_nb (int 11)
location (varchar 20)
availability (varchar 1) //this can be 'Y' or 'N'
Table reservation :
reservation_nb (int 10 auto_increment)
spot_nb (int 11)
uin (varchar 8; null)
persons_nb (int 5)
price (int 11)
email (varchar 60)
And for php I have the following code:
$query5 = $conn->prepare("SELECT MAX(spot_nb) from camping where capacity=2 and availability='Y'");
$query5->execute();
$result = $query5->fetch(PDO::FETCH_ASSOC);
$id = (int) $result;
to get the max value from table camping and insert into reservation with this code
$query6 = $conn->prepare("INSERT INTO reservation (price, persons_nb, email, spot_nb) VALUES (:price, 2, :email, :id);");
$query6-> bindParam(':price', $campingNumber);
$query6-> bindParam(':email', $email);
$query6-> bindParam(':id', $id);
But every time query6 is executed, the spot_nb that is inserted is 1.
Thank you, Alex.