Situation
I have a submit form. With this form, users are able to reserve a table in a restaurant. Which each submit there is data send to the database with the wp_insert_post
function. For example the user_ip
and the datum_nieuwe_reservering
(explained later). I want to use this to check if the user is allowed to submit a new reservation(prevent spamming). I have tried a couple of thing, but it's not working. See code below.
Question
How can I get this to work? What am I doing wrong?
CODE
reserving.php
<!-- CODE WHEN POST = SUBMIT, MAKE A NEW RESERVATION.
=========================================== -->
<?php
global $wpdb;
$user_ip_db = getUserIP();
$date = date("d-m-Y H:i:s");
//echo $date;
$check_user_ip = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'user_ip_reservering' AND meta_value = '$user_ip_db'");
$check_time_new = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'datum_nieuwe_reservering'");
print_r($check_time_new);
if ( isset($_POST['submit_reservering']) ) {
if ( (empty($check_user_ip)) && $date > $check_time_new ) {
create_reservering();
echo "Your reservation has been send";
} else {
echo 'You have already reserved';
}
}
?><!-- end CODE FOR MAKING RESERVATION-->
Plugin file
//Using this function to send the current day + 1 day to the database
//with a hidden text field named `datum_nieuwe_reservering`(show below)
//and in the end check if current date >= `datum_nieuwe_reservering`
<?php
function getDateTime(){
date_default_timezone_set('Europe/Amsterdam');
$next_day = time() + (1 * 24 * 60 * 60);
$date_now = date('d-m-Y H:i:s');
$date_tomorrow = date('d-m-Y H:i:s', $next_day);
echo $date_tomorrow;
}
?>
Hidden field for datum_nieuwe_reservering
<input type='hidden' value='<?php echo getDateTime(); ?>' name='datum_nieuwe_reservering'>
NOTE: The submit form is working correctly with the if (empty($check_user_ip)) { };
code only. So I'm struggle to add the date in the if statement too.
I hope someone can help me in the right direction!
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire