Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
Created October 1, 2015 16:31
Show Gist options
  • Save mmilosheski/0ec054737f652bca9356 to your computer and use it in GitHub Desktop.
Save mmilosheski/0ec054737f652bca9356 to your computer and use it in GitHub Desktop.
wordpress add to database table
/// HTML PAGE TEMPLATE SHOULD HAVE THIS CODE (KEEP IN MIND THAT THE INSERT.PHP IS IN THE TEMPLATE DIR
<form action="<?php echo get_template_directory_uri(); ?>/insert.php" method="post">
Name:<input type="text" name="name"/>
<input type="submit" name="submit"/>
</form>
/// THE INSERT.PHP FILE SHOULD HAVE THIS CODE
<?php
global $wpdb
$name = $_POST['name'];
$wpdb->insert( 'bank', array( 'name' => $name ), array( '%s' ) )
?>
@thohid44
Copy link

thohid44 commented Oct 2, 2015

Fatal error: Call to a member function insert() on a non-object in C:\xampp\htdocs\wordpress\wp-content\themes\poilot\insert.php on line 9

why?

@thohid44
Copy link

thohid44 commented Oct 2, 2015

when use this code; file name insert.php

insert( 'bank', array( 'name' => $name ), array( '%s' ) ) ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment