Q: Wordpress. Insert form values to custom table How can i on click on submit send values to my custom mysql table??
Form html:
 <form action="/ekz.php" method="post">
 <input type="text" name="jjkk1">
 <input type="text" name="jjkk2">
 <input type="text" name="jjkk3">
 <input type="text" name="jjkk4">
 <input type="submit" name="submit">
 </form>

Table name is wp_ekz2020:
Try doing like this :
<?php
if(isset($_POST['submit']))
{
 global $wpdb;

 $a=$_POST['jjkk1'];
 $b=$_POST['jjkk2'];
 $c=$_POST['jjkk3'];
 $d=$_POST['jjkk4'];

$wpdb->insert( 'wp_ekz2020', array( 'num1' => $a, 'num2' => $b,'num3' => $c, 
 'num4' => $d), array( '%s', '%s','%s', '%s'  ) );
}

?>


A: please try to place both html and php in single file
here is code i have try and it works
<form action="<?php the_permalink(); ?>" method="post">
     <input type="text" name="num1">
     <input type="text" name="num2">
     <input type="text" name="num3">
     <input type="text" name="num4">
     <input type="submit" name="submit">
 </form>

if(isset($_POST['submit']))
{
 
 function insertnumber(){
  global $wpdb;
  $num1 = $_POST['num1'];
  $num2 = $_POST['num2'];
  $num3 = $_POST['num3'];
  $num4 = $_POST['num4'];
  $table_name = "newtab";
 $wpdb->insert( $table_name, array(
    'num1' => $num1,
    'num2' => $num2,
    'num3' => $num3,
    'num4' => $num4
    ) );
}
insertnumber();
}

put <?php the_permalink(); ?> in your form action
i hope above code will help you : )
change table name and also variable

A: in this case, whenever you submit the form with action attribute then the page gets reloaded, and '$wpdb' returns null. So this will cause error.
To prevent this you have to include 'wp-load.php' in your file or you can use
add_action('init', 'your_function_name')

