benchew0904 Posted October 30, 2011 Share Posted October 30, 2011 Hi I need some help. I wanted to create a start and end event date using date picker and also after selecting the start and end date, it will calculate the number of days (duration). I have found the date picker which can do what I want but I need help to post the duration to another php page when user click on submit. Can anyone help me. You might want to refer to my attach PHP page and here is the link to the datepicker, http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.html Thanks Ben Chew [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/ Share on other sites More sharing options...
joel24 Posted October 30, 2011 Share Posted October 30, 2011 it should be posting the dates to the confirmation.php file... does that file exist and is it located in the same directory? what code is in that file? if you want to post the difference you'll have to change <li style="list-style: none;" id="duration"></li> to <input type='text' name='duration' id='duration' /> also, you've got a superfluous " at the end of your <form> tag... <form name ="drop_list" method = "POST" action ="confirmation.php" "> //should be <form name ="drop_list" method = "POST" action ="confirmation.php"> Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283406 Share on other sites More sharing options...
benchew0904 Posted October 30, 2011 Author Share Posted October 30, 2011 Thanks joel24 for the reply. Yes, the file exist and it's in the same directory. I have tried changing to <input type='text' name='duration' id='duration' /> but after I changed, the number of days between the start and end days will not be be shown. And I have remove the superfluous ". Thanks for pointing out my careless mistake. And this is in the confirmation.php page <?php $startDate = $_POST['startDate']; $endDate = $_POST['endDate']; $duration = $_POST['duration']; ?> <table style="width: 45%" > <tr> <td>Event Start Date</td> <td><?php echo $startDate; ?></td> </tr> <br/> <tr> <td>Event End Date</td> <td<?php echo $endDate; ?></td> </tr> <br/> <tr> <td>No. of Days Selected</td> <td><?php echo $duration; ?></td> </tr> </table> Please do advise again. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283414 Share on other sites More sharing options...
joel24 Posted October 30, 2011 Share Posted October 30, 2011 try add this to your confirmation.php page and tell us what it prints print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283520 Share on other sites More sharing options...
benchew0904 Posted October 31, 2011 Author Share Posted October 31, 2011 This is the result after I include print_r($_POST); Array ( [startDate] => 31/10/2011 [endDate] => 24/11/2011 [duration] => [submit] => Submit ) Event Start Date 31/10/2011 Event End Date No. of Days Selected And it wil not show my event end date also. Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283562 Share on other sites More sharing options...
benchew0904 Posted October 31, 2011 Author Share Posted October 31, 2011 Sorry, ignore my previous post. This is the result after I include print_r($_POST); Array ( [startDate] => 31/10/2011 [endDate] => 24/11/2011 [duration] => [submit] => Submit ) Event Start Date 31/10/2011 Event End Date 24/11/2011 No. of Days Selected Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283571 Share on other sites More sharing options...
joel24 Posted October 31, 2011 Share Posted October 31, 2011 you're not posting the duration across... you need to add the value to a form element using javascript or you can use PHP to determine the days between... You'll need to use a '-' as a seperator rather than '/' - this tells the strtotime() function that it will be a european date format (d-m-y) rather than american (m/d/y) #get unix timecode of dates (seconds past since 1st Jan 1970) - ensure they are either d-m-y or m/d/y $start=strtotime($_POST['startDate']); $end=strtotime($_POST['endDate']); #subtract start from end and divide by seconds in day to determine days... $days = $end-$start / (60*60*24); echo $days; Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283583 Share on other sites More sharing options...
benchew0904 Posted October 31, 2011 Author Share Posted October 31, 2011 Hi This is the output Array ( [startDate] => 01-11-2011 [endDate] => 03-11-2011 [duration] => [submit] => Submit ) Event Start Date 01-11-2011 Event End Date 03-11-2011 No. of Days Selected 1320263121 Please do advise again on the days selected Thanks Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283591 Share on other sites More sharing options...
joel24 Posted October 31, 2011 Share Posted October 31, 2011 sorry, my bad #get unix timecode of dates (seconds past since 1st Jan 1970) - ensure they are either d-m-y or m/d/y $start=strtotime($_POST['startDate']); $end=strtotime($_POST['endDate']); #subtract start from end and divide by seconds in day to determine days... $days = ($end-$start) / (60*60*24); echo $days; Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283599 Share on other sites More sharing options...
benchew0904 Posted October 31, 2011 Author Share Posted October 31, 2011 Thanks joel24 for helping me to solve this problem and I also learnt a valuable lesson. Really appreciate it Once again, thanks Quote Link to comment https://forums.phpfreaks.com/topic/250094-how-to-post-to-another-php-page/#findComment-1283644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.