I did a POST form and try to sign in to the Wordpress database is showing this error.

Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\teste\wp-content\themes\twentysixteen\records.php on line 45


  $nome = "";
  $email = "";
  $estilo = "";
  $experiencia = "";
  $altura = "";
  $peso = "";    

     $nome = $_POST['nome'];
     $email = $_POST['email'];
     $estilo = $_POST['estilo'];
     $experiencia = $_POST['experiencia'];
     $altura = $_POST['altura'];
     $peso = $_POST['peso'];    

     record_user($nome, $email, $estilo, $experiencia, $altura, $peso);

function record_user($nome, $email, $estilo, $experiencia, $altura, $peso){          

    global $wpdb;
     // the name of our table
    $table = 'user';

    // data is an array with the format column_name => data
    $data = array(      
      'nome' => $nome,
      'email' => $email,
      'estilo' => $estilo,
      'exp' => $experiencia,
      'altura' => $altura,
      'peso' => $peso

    // run the insert. LINE 45 BELOW
    $updated = $wpdb->insert( $table, $data );

    // if it didn't update get the error
    if ( ! $updated ) {



<form class="form-validation" method="post" id="myForm" action="<?php bloginfo('template_url'); ?>/records.php">

What can it be?

  • Perhaps this is another problem waiting to happen: I think this line has a typo: $wpbb->print_error(); And should be: $wpdb->print_error(); – Andy Macaulay-Brook Jul 24 '16 at 19:21
  • Because your form action goes directly to your theme file and runs it, you aren't including any of WordPress in your code run and so $wpdb is undefined. Instead of calling a theme file you should hook your form processing into WP properly. Where exactly do you put your form? – Andy Macaulay-Brook Jul 24 '16 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.