JavaScript — динамические поля не сохраняются в базе данных

Динамические поля не сохраняются в базе данных

Я пишу код для добавления динамических полей и сохранения их в базе данных, но когда я сохраняю, он не сохраняется, ниже приведен мой код, может кто-нибудь сказать, пожалуйста, что я делаю не так Это код плагина, где у меня есть добавлена ​​форма для динамического добавления полей и сохранения данных Это код формы:

  {amp}lt;?php /* Plugin Name: Link Changer Description: Changes the button link after certain clicks Version: 1.0 Text Domain: button-link-changer */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } add_action( 'admin_menu', 'link_changer_menu' ); $con = mysqli_connect('localhost','aejaz_wp1','Q.gslkbUNCOT2zZUVSw82','aejaz_wp1'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } else{ echo ''; } global $jal_db_version; $jal_db_version = '1.0'; function jal_install() { global $wpdb; global $jal_db_version; $table_name = $wpdb-{amp}gt;prefix . 'liveshoutbox'; $charset_collate = $wpdb-{amp}gt;get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, links varchar(55) DEFAULT '' NOT NULL, hitsmade mediumint(9) NOT NULL, hitstocount mediumint(9) NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); add_option( 'jal_db_version', $jal_db_version ); } function jal_install_data() { global $wpdb; $welcome_name = 'Mr. WordPress'; $welcome_text = 'Congratulations, you just completed the installation!'; $table_name = $wpdb-{amp}gt;prefix . 'liveshoutbox'; $wpdb-{amp}gt;insert( $table_name, array( 'time' ={amp}gt; current_time( 'mysql' ), 'name' ={amp}gt; $welcome_name, 'text' ={amp}gt; $welcome_text, ) ); } register_activation_hook( __FILE__, 'jal_install' ); register_activation_hook( __FILE__, 'jal_install_data' ); function link_changer_menu(){ $page_title = 'Link Changer'; $menu_title = 'Button Link Changer'; $capability = 'manage_options'; $menu_slug = 'Button-Link-Changer'; $function = 'extra_post_info_page'; $icon_url = 'dashicons-media-code'; $position = 6; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); add_action( 'admin_init', 'link_register_settings' ); } function link_register_settings() { // Let's create and register the Sections. // - register_setting( $option_group, $option_name, $sanitize_callback ); register_setting('button-link-changer', 'link_options', 'link_options_sanitize'); } //to save options as array create input fields function bp_options_sanitize($input){ $input['link_one'] = sanitize_text_field($input['link_one']); $input['link_two'] = sanitize_text_field($input['link_two']); $input['link_hits'] = sanitize_text_field($input['link_hits']); $input['links'] = sanitize_text_field($input['links']); return $input; } // end link_options_sanitize // Let's create the Main Page function extra_post_info_page(){ #saving plugin options to database from form ?{amp}gt; {amp}lt;h1{amp}gt;Button Link Changer{amp}lt;/h1{amp}gt; {amp}lt;form method="post" action="options.php"{amp}gt; {amp}lt;?php settings_fields( 'button-link-changer' ); ?{amp}gt; {amp}lt;?php //do_settings_sections( 'button-link-changer' ); ?{amp}gt; {amp}lt;?php $link_options = get_option('link_options') ?{amp}gt; {amp}lt;table class="form-table"{amp}gt; {amp}lt;tr valign="top"{amp}gt; {amp}lt;th scope="row"{amp}gt;Link one{amp}lt;/th{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input type="text" name="link_options[link_one]" value="{amp}lt;?php echo esc_attr($link_options['link_one']); ?{amp}gt;" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;tr valign="top"{amp}gt; {amp}lt;th scope="row"{amp}gt;Link two{amp}lt;/th{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input type="text" name="link_options[link_two]" value="{amp}lt;?php echo esc_attr($link_options['link_two']) ?{amp}gt;" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;tr valign="top"{amp}gt; {amp}lt;th scope="row"{amp}gt;Link Hits{amp}lt;/th{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input type="text" name="link_options[link_hits]" value="{amp}lt;?php echo esc_attr($link_options['link_hits']) ?{amp}gt;" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;?php submit_button(); ?{amp}gt; {amp}lt;/form{amp}gt; {amp}lt;form name="add_me" id="add_me"{amp}gt; {amp}lt;table id="dynamic"{amp}gt; {amp}lt;input type="text" name="name[]" placeholder="Enter Your Name" /{amp}gt; {amp}lt;button type="button" name="add" id="add_input"{amp}gt;Add{amp}lt;/button{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;input type="button" name="submit" id="submit" value="Submit" /{amp}gt; {amp}lt;/form{amp}gt; {amp}lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.min.js"{amp}gt;{amp}lt;/script{amp}gt; {amp}lt;script{amp}gt; $(document).ready(function() { var i = 1; $('#add_input').click(function() { i  ; $('#dynamic').append('{amp}lt;tr id="row'   i   '" {amp}gt;{amp}lt;td{amp}gt;{amp}lt;input type="text" name="name[]" placeholder="Enter Your Name"/{amp}gt;{amp}lt;/td{amp}gt;{amp}lt;td{amp}gt;{amp}lt;button type="button" name="remove" id="'   i   '" class="btn_remove"{amp}gt;Remove{amp}lt;/button{amp}gt;{amp}lt;/td{amp}gt;{amp}lt;/tr{amp}gt;'); }); $(document).on('click', '.btn_remove', function() { var button_id = $(this).attr("id"); $('#row'   button_id   '').remove(); }); $('#submit').click(function() { $.ajax({ url: "insert.php", method: "POST", data: $('#add_me').serialize(), success: function(data) { alert(data); $('#add_me')[0].reset(); } }); }); }); {amp}lt;/script{amp}gt; {amp}lt;?php //fetching data from database global $wpdb; $results = $wpdb-{amp}gt;get_results( "SELECT option_value FROM $wpdb-{amp}gt;options WHERE option_name='link_options'"); if(!empty($results)) { // output data of each row $arrayvalues=$results[0]-{amp}gt;option_value; $unserialized_categoriesx = unserialize($arrayvalues); echo $unserialized_categoriesx['link_one']; $varlinkone = $unserialized_categoriesx['link_one']; echo "{amp}lt;/br{amp}gt;"; echo $unserialized_categoriesx['link_two']; $varlinktwo = $unserialized_categoriesx['link_two']; $unserialized_categoriesx['link_hits']; $varlinkhits =$unserialized_categoriesx['link_hits']; } $hits = 0; //counting and comparing hits if ($hits[0]{amp}lt;= $varlinkhits) { $buttonlink="$varlinkone"; } else { $buttonlink="$varlinktwo"; } echo $hits[0]; ?{amp}gt; {amp}lt;a href="{amp}lt;?php echo $_SESSION["button_url"] ?{amp}gt;" {amp}gt;Join Whatsapp Group{amp}lt;/a{amp}gt;; {amp}lt;?php $_SESSION["button_url"] = $buttonlink; ?{amp}gt; {amp}lt;?php } function link_button_function() {?{amp}gt; {amp}lt;a href="{amp}lt;?php echo $_SESSION["button_url"] ?{amp}gt;" id="clickme"{amp}gt;Join Whatsapp Group{amp}lt;/a{amp}gt;; {amp}lt;?php } add_shortcode('button_link', 'link_button_function'); 

Это insert.php

  {amp}lt;?php $conn = mysqli_connect("localhost", "root", "", "aejaz_wp1"); $number = count($_POST["name"]); if($number {amp}gt; 0) { for($i=0; $i{amp}lt;$number; $i  ) { if(trim($_POST["name"][$i] != '')) { $sql = "INSERT INTO wp_liveshoutbox(links) VALUES('".mysqli_real_escape_string($conn, $_POST["name"][$i])."')"; mysqli_query($conn, $sql); } } echo "Data Inserted Successfully"; } else { echo "Enter Your Name"; } ?{amp}gt; 
Понравилась статья? Поделиться с друзьями:
JavaScript & TypeScript
Adblock
detector