Home > Enterprise >  Wordpress plugin - insert data from textbox
Wordpress plugin - insert data from textbox

Time:07-27

        <form action="" method="post">
        <label>Ingredient Descriptions</label><input type="text" name="ıngredient"/>
        <p style="text-align: center;" >
        <input type="submit" name="submit" value="submit" />
        </p>
        </form>

        <?php
        function display()
        {   
            global $wpdb;
            $ıngredient = $_POST["ıngredient"];
            $wpdb->insert ("test-enes",array('ıngredient'=>$ıngredient));
            print $ıngredient = $_POST['ıngredient'];
        }
        if(isset($_POST['submit']))
        {
        display();
        } 
        ?>

I am trying to add data to wordpress database. But I couldn't find what I did wrong. I'm new to this, can you please help me. Thanks

CodePudding user response:

You need to add it with hook, put this code functions.php

add_action('wp', 'submitform');

function submitform(){

if(isset($_POST['submit']))
      {   
          global $wpdb;
          $ıngredient = $_POST["ıngredient"];
          $wpdb->insert ("test-enes",array('ıngredient'=>$ıngredient));
          print $ıngredient = $_POST['ıngredient'];
      } 
}
  • Related