i have created a plugin for wordpress to sbmit form dtails to wordpress database. I created a table in cpanel phpmyadmin called 'wp_in_booking'. im trying to send the form data, but it can not get through. Here is my code.Data is not sent to the database. please help. thank you

function in_booking_form(){ 
    <link href="<?php echo plugin_dir_url(__FILE__).'/files/jquery.datetimepicker.css'; ?>" rel="stylesheet" type="text/css">
    <script src="<?php echo plugin_dir_url(__FILE__).'/files/jquery.datetimepicker.js'; ?>"></script>

    <form class="in-checkout-form" action=""  method="post">
        <div class="in-booking-section">
        <input required type="text" id="date_timepicker_start" class="in-dates" name="check_in" placeholder="check-in">
        // there is other javascript code here

        <input type="hidden" name="total_amount" value="">
        <input type="hidden" name="adults" value="1">
        <input type="hidden" name="children" value="0">
        <input type="hidden" name="infants" value="0">
      <input type="submit" class="in-request-to-book" value="Request to Book" name="submit">
      global $wpdb;

    // $table = $wpdb->prefix . "wp_in_booking";
    $check_in = $_POST['check_in'];
    $check_out = $_POST['check_out'];
    $total_amount = $_POST['total_amount'];
    $adults  =$_POST['adults'];
    $children = $_POST['children'];
    $infants = $_POST['infants'];



    $result = $wpdb->insert('wp_in_booking', array(
      'total_amout' =>$total_amount,

      echo "Booking Successful";
      echo "Booking Unsuccessful! Please Contact Support";



    return ob_get_clean();


and my database structure

enter image description here

  • "// there is other javascript code here" Such as? Does it do anything on form submission? – Jacob Peattie Jun 1 '18 at 14:22
  • What is the value of $result after you run the db query. If an error was encountered; it should show there if you var-dump the variable. – josh Jun 1 '18 at 14:22
  • @JacobPeattie no, the Javascript is just for a few onclick additions. @josh the link is working fine, because datepicker - which was the intended functionality is working fine. var_dump($result) returns false – Timothy Mach Jun 1 '18 at 14:28

I think I found out where the problem was. the datatype for check_in and check_out in the database was set to DATETIME Instead of DATE yet the code $check_in_db=date("Y-m-d",strtotime($check_in)); was converting it to date. I don't know why it prevented entry of the other data, but after changing that, it is working now. to use date time, use this $check_in_db=date("Y-m-d H:i:s",strtotime($check_in));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.