I'm a bit of a newbie to PHP/MySQL, so please excuse me if I seem ignorant of something seemingly obvious. I'm writing a booking system for a holiday home rental company. I'm building it up slowly. What I have so far is trying to calculate the number of nights that a person will stay based on the date that they arrive and depart.
This is what I have so far: -
<html> <head><title>Booking Form</title></head> <body> <form action="calculate.php" method="post"> Date of arrival: <input type="text" name="arrival"> Date of departure: <input type="text" name="departure"> <input type="Submit" value="Submit"><input type="Reset" value="Reset"> </form> </body> </html>
The code above is for the user to insert the dates of arrival and departure.
<?php // Connects to your Database mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("dissertation") or die(mysql_error()); $sql="SELECT datediff('$departure','$arrival')" or die(mysql_error()); $result = mysql_query($sql); $row = mysql_fetch_row($result); $insert = "INSERT INTO booking (arrival, nights, departure) VALUES ('".$_POST['arrival']."', '$result', '".$_POST['departure']."')"; $holiday = mysql_query($insert); ?>
Using the code above, I want to work out the number of nights a person is staying for, and enter that with the dates of arrival and departure into the database. Currently, when I run the code, I get 'Resource id #3' in the 'nights' column of the table. Doing a search on Google would imply that I'm missing something, but i can't see what.
Below is the code for my table. The reason for such a big 'nights' column is so I can see the full error that I'm getting currently.
create table booking ( id INT primary key auto_increment, arrival date NOT NULL, nights varchar(100) NOT NULL, departure date NOT NULL );
Thanks in advance for any tips! :)
Edited by mikeypc2010: Noticed a $ extra in my query, but removing hasn't solved the problem