Monday, December 5, 2022
HomeWordPress Developmentphp - Cannot ship kind information to wpdb when URL has question...

php – Cannot ship kind information to wpdb when URL has question string


I’ve a desk referred to as wp_invites which accommodates an inventory of invitees. This desk accommodates a column referred to as reference, which is added to the URL as a question param as a way to customise their invite (i.e. take a look at.com/?ref=1e232ewf2 ).

On my web page, I’ve an RSVP kind, and the concept is to submit the shape information to a different customized desk referred to as wp_rsvp.

With my present method under, at any time when I submit the shape, I get a 404 error:

This take a look at.take a look at web page can’t be discovered
No internet web page was discovered for the online deal with: http://take a look at.take a look at/?ref=1e232ewf2
HTTP ERROR 404

I’ve tried leaving kind motion to an empty string (motion=""), however no luck.

<kind motion="<?php get_the_permalink(); ?>" technique="submit">
  <fieldset class="fieldset">
    <enter sort="textual content" title="title" placeholder="Your title*" required />
  </fieldset>
  <fieldset class="fieldset">
    <enter sort="e mail" title="e mail" placeholder="Your e mail*" required />
  </fieldset>
  <fieldset class="fieldset">
    <textarea title="message"></textarea>
  </fieldset>
</kind>

</php

international $wpdb;

/*
* on submit, ship kind information to DB
*/

if(isset($_POST['submit'])){
  insert_row();
}

/*
* get information from fields
*/

operate insert_row(){

  $rsvp_table = $wpdb->prefix . 'invitations';

  // get information from fields
  $title = sanitize_text_field( $_POST['name']);
  $e mail = sanitize_text_field( $_POST['email']);
  $message = sanitize_text_field( $_POST['message']);

  // retailer information in array
  $information = array(
    'form_completed_by' => $title,
    'e mail' => $e mail,
    'notes' => $message
  );

  var_dump($information);

  // arrange codecs for database SQL injection safety
  $codecs = array(
    '%s',  // form_completed_by ought to be an string
    '%s',
    '%s'
  );

  // Debugging: Activate error reporting for db to see if there is a database error
  $wpdb->show_errors();

  // Truly try and insert the info
  $wpdb->insert($rsvp_table, $information, $codecs);

}

?>

I’m operating all this code in a single file (rsvp-form.php).

My information dumps (i.e. var_dump($information)) additionally present nothing. No new leads to the wp_rsvp desk naturally. Uncertain the place it is falling aside?

Newest method

<?php $reference = ( isset( $_GET['ref'] ) ) ? sanitize_text_field( $_GET['ref'] ) : ''; ?>

<kind motion="<?php echo esc_url( get_the_permalink() ); ?>?<?php echo $reference; ?>" technique="submit">
  <enter sort="hidden" title="rsvp_nonce" worth="<?php echo wp_create_nonce( 'rsvp_nonce' ); ?>" />
  <fieldset class="fieldset">
    <enter sort="textual content" title="title" placeholder="Your title*" required />
  </fieldset>
  <fieldset class="fieldset">
    <enter sort="e mail" title="e mail" placeholder="Your e mail*" required />
  </fieldset>
  <fieldset class="fieldset">
    <textarea title="message"></textarea>
  </fieldset>
</kind>

</php

international $wpdb;

/*
* on submit, ship kind information to DB
*/

if(isset($_POST['submit'])){
  insert_row();
}

/*
* get information from fields
*/

operate insert_row(){

  $rsvp_table = $wpdb->prefix . 'rsvp';

  // get information from fields & sanitize them
  $title = sanitize_text_field( $_POST['name']);
  $e mail = sanitize_text_field( $_POST['email']);
  $message = sanitize_text_field( $_POST['message']);

  // retailer information in array
  $information = array(
    'form_completed_by' => $title,
    'e mail' => $e mail,
    'notes' => $message
  );

  var_dump($information);

  // arrange codecs for database SQL injection safety
  $codecs = array(
    '%s',  // form_completed_by ought to be an string
    '%s',
    '%s'
  );

  // Debugging: Activate error reporting for db to see if there is a database error
  $wpdb->show_errors();

  //  try and insert the info
  if ( ! wp_verify_nonce( $_POST['rsvp_nonce'], 'rsvp_nonce' ) ) {
    // Nonce verification failed, don't insert information
    return;
  } else {
    $wpdb->insert($rsvp_table, $information, $codecs);
  }

  if ( $wpdb->last_error !== '' ) {
    // There was an error
    echo $wpdb->last_error;
  } else {
    // Success
    echo 'Information was inserted efficiently';
  }

}

?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments