Form doesnt save to database


It is my first form trying on wordpress.I changed some names such as “name”,”e-mail” etc. to “name1” , “email1” etc.Because without these changing, submit button refers to 404 page.

There is no any registration on database when I check it

I dont know any idea about what is the spesific code as problem so I
give my all codes.If you know enough information, probably you can
solve this easyly.But if you dont enough information, probably you
will give negative point to question and go away from my question.Or
maybe, you can close my question and write “give us spesific
code/question”.I write again, there is no problem with my question or
asking style, it is completly your information.

<!-- data mata -->
    <div class="reservation-info">
        <form class="reservation-form" method="post">
            <h2>Make a reservation</h2>
            <div class="field">
                <input type="text" name="name1" placeholder="Name" required>
            <div class="field">
                <input type="datetime-local" name="date1" placeholder="Date" step="300" required>
            <div class="field">
                <input type="text" name="email1" placeholder="E-Mail">
            <div class="field">
                <input type="tel" name="phone1" placeholder="Phone Number" required>

            <div class="field">
                <textarea name="message1" placeholder="Message" requires></textarea>

            <div class="g-recaptcha" data-sitekey="6LeKTjMUAAAAAJuZI0qqIBRp92slJoG4SESblWHw"></div>

            <input type="submit" name="reservation1" class="button" value="Send">

            <input type="hidden" name="hidden" value="1">

    function lapizzeria_database(){
        global $wpdb;

        global $lapizzeria_db_version;
        $lapizzeria_db_version = "1.0";

        $table = $wpdb->prefix . 'reservations1';

        $charset_collate = $wpdb->get_charset_collate();

        // SQL Statement

        $sql = "CREATE TABLE $table ( 
                id mediumint(9) NOT NULL AUTO_INCREMENT, 
                name1 varchar(50) NOT NULL,
                date1 datetime NOT NULL,
                email1 varchar(50) DEFAULT '' NOT NULL,
                phone1 varchar(10) NOT NULL,
                message1 longtext NOT NULL,
                PRIMARY KEY (id)
        ) $charset_collate; ";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    add_action('after_setup_theme', 'lapizzeria_database');

function lapizzeria_save_reservation() {

    if(isset($_POST['reservation1']) && $_POST['hidden'] == "1") {
              // read the value from recaptcha response
              $captcha = $_POST['g-recaptcha-response'];

              // Send the values to the server
              $fields = array(
                  'secret' => '6LeKTjMUAAAAAFeaj6Hq941AFvASw9sBJjeiCDyB',
                  'response' => $captcha,
                  'remoteip' => $_SERVER['REMOTE_ADDR']

              // Start the request to the server

              $ch = curl_init('');

              // configure the request
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
              curl_setopt($ch, CURLOPT_TIMEOUT, 15);

              // Send the encode values in the URL 
              curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));

              // Read the return value
              $response = json_decode(curl_exec($ch));
              if($response->success) {
                          global $wpdb;
                          $name = sanitize_text_field( $_POST['name1'] ) ;
                          $date = sanitize_text_field( $_POST['date1'] ) ;
                          $email = sanitize_email( $_POST['email1'] );
                          $phone = sanitize_text_field( $_POST['phone1'] ) ;
                          $message = sanitize_text_field( $_POST['message1'] ) ;

                          $table = $wpdb->prefix . 'reservations1';

                          $data = array(
                            'name1' => $name1,
                            'date1' => $date1,
                            'email1' => $email1,
                            'phone1' => $phone1,
                            'message1' => $message1

                          $format = array(
                          $wpdb->insert($table, $data, $format );

                          $url = get_page_by_title('Thanks for your reservation!');
                          wp_redirect( get_permalink($url) );


add_action('init', 'lapizzeria_save_reservation');


function lapizzeria_reservations() { ?>
  <div class="wrap">
      <table class="wp-list-table widefat striped">
                  <th class="manage-column">ID</th>
                  <th class="manage-column">Name</th>
                  <th class="manage-column">Date of Reservation</th>
                  <th class="manage-column">Email</th>
                  <th class="manage-column">Phone Number</th>
                  <th class="manage-column">Message</th>
                  <th class="manage-column">Delete</th>

                global $wpdb;
                $table = $wpdb->prefix . 'reservations1';
                $reservations = $wpdb->get_results("SELECT * FROM $table", ARRAY_A); 
                foreach($reservations as $reservation): ?>
                        <td><?php echo $reservation['id']; ?></td>
                        <td><?php echo $reservation['name1']; ?></td>
                        <td><?php echo $reservation['date1']; ?></td>
                        <td><?php echo $reservation['email1']; ?></td>
                        <td><?php echo $reservation['phone1']; ?></td>
                        <td><?php echo $reservation['message1']; ?></td>
                            <a href="#" class="remove_reservation" data-reservation="<?php echo $reservation1['id']; ?>">Remove</a>
                <?php endforeach; ?>

<?php }

, , , Faruk riza 3 years 2020-03-31T16:50:51-05:00 0 Answers 85 views 0

Leave an answer