I'm trying to produce a wordpress plugin for Wordpress which enables the consumer to go in a title right into a text box. The consumer then clicks 'submit' which title is taken and put into the database. However presently whenever you press submit, it returns a PHP error:

Fatal error: Call to some member function query() on the non-object in /home/matthew/public_html/demo/wordpress-content/plug ins/premium-slider/admin.php online 49

Line 49 may be the following code:


This really is perfectly valid code based on Wordpress's lessons.

This is actually the overall code segment:

function print_admin_form() {
 if (isset($_POST['addnew'])) {

 $new = $_REQUEST['name'];

 $name = escape($new);

  $sql = "INSERT INTO $table_name_cat (name) VALUES('$new')";
  echo $name; } 
 else {
  echo '<div id="message" class="error" style="width:750px;"><p><strong>Failed to add new slider.</strong></p></div>'; }?>

<div class="wrap">
<h2>Easing Slider</h2>
 <form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>&updated=true">
   <div class="metabox-holder" style="width:402px;float:left;">
    <div class="postbox">
      <h3><span>Slider title:</span></h3>
      <h4 style="margin:10px;">Name:</h4><input type="text" name="name" style="width: 380px;margin:10px;margin-top:0px;"/>
 <input type="submit" class="button-primary" name="addnew" value="Save Changes" style="" />
 </div> <?php }

try :

global $wpdb;

as first type of your print_admin_form function.