Title: $wpdb not loading?
Last modified: March 13, 2022

---

# $wpdb not loading?

 *  [hsysgrp](https://wordpress.org/support/users/hsysgrp/)
 * (@hsysgrp)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/)
 * Am replacing working sql statements with $wpdb methods. I have replaced SELECT
   statements, but have not been able to UPDATE. I have included all of the code,
   not knowing what is causing the fail. The error I get is Uncaught Error: Call
   to a member function show_errors() on null in /home4/hsysgrpc/public_html/wp-
   content/themes/twentytwelve-child/custom-page_InputMemberID-wpdb.php:17; or if
   I comment out the show_errors() statement, the same Call to a member function
   on null points to the UPDATE statement. Thank you for your help.
 *     ```
       <?php
       // custom-page_InputMemberID-wpdb.php 3/13/2022
       /**
        * Template Name: Input Member ID wpdb
        *
        * @package WordPress
        * @subpackage Twenty_Twelve
        * @since Twenty Twelve 1.0
        */
   
       include 'myFuncs.php';
   
       $link = connect(); 
   
       global $wpdb;
   
       $wpdb->show_errors(true);
       if($link === false){    die("ERROR: Could not connect. " . mysqli_connect_error());
       }  
   
   
       if(isset($_POST['search'])) {
       	$searchf = $_POST['searchf'];
       	$searchf = preg_replace("#[^A-Za-z\' -]#i","",$searchf); //only characters  and spaces, -
       	$searchq = $_POST['search'];
       	$searchq = preg_replace("#[^A-Za-z\' -]#i","",$searchq); 
       	$searchn = $_POST['memberNumber'];
   
       	echo "<br>$searchf<br>";
       	echo "<br>$searchq<br>";
       	echo "<br>$searchn<br>";
   
       	$FirstName = $searchf;
       	echo $FirstName;
       	echo "<br>";
       	$LastName = $searchq;
       	echo "LastName = " . $LastName;
       	echo "<br>";
       	$MemberID = $searchn; //New National Number
       	echo $MemberID;
       	echo "<br>";
       	$tablename = "AAUW_New_Members";
       	echo "AAUW_New_Members "  . $tablename;
       	echo "<br>";
       	$data = $MemberID;
       	echo $data;
       	echo "<br>";
       	$wherecondition = $searchq;
       	echo "<br>";
       	echo "LastName = " . $wherecondition;
       	$updated = $wpdb->update($tablename, 
       					array('MemberID' => $searchn
       						  ), 
       					array('LastName' =>$searchq
       						 )		 
       				);
       	echo print_r($updated);
   
       	"<br>";
   
   
       } //Close isset search
   
   
       ?>
       <html>
       <head>
       <title>Search for ID by FirstName,Lastname</title>
       </head>
       <body>
       <form id = 1 action = "/wp-content/themes/twentytwelve-child/custom-page_InputMemberID-wpdb.php" method="POST"> 
       	<p>
       		Input New Member ID for record to be moved from AAUW_New_Members to AAUW_Members
       	</p>
       	<input type ="text" name = "searchf" placeholder= "Search for First Name..."/>
       	<input type ="text" name = "search" placeholder= "Search for Last Name..."/>
       	<input type ="text" name = "memberNumber" placeholder= "Input MemberNumber..."/>
       	<input type = "submit" value = "search..." />
       	</form>
   
       	</body>
       </html>
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwpdb-not-loading%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454360)
 * Are you also loading the entire WordPress environment? Or in other words, how
   do you embed this PHP code into WordPress?
 *  Thread Starter [hsysgrp](https://wordpress.org/support/users/hsysgrp/)
 * (@hsysgrp)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454472)
 * Site hsysgrp.com
    Page New Member sub Page Input Member ID Permalink _[ redundant
   link removed ]_ Template Name: Input Member ID wpdb custom-page_InputMemberID-
   wpdb.php I have pages where the get_results SELECT method works fine, both INSERT
   and UPDATE statements give me the same call to a member function on null error.
   I used to think it was syntax, now I’m really puzzled.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454501)
 * I’m afraid I don’t follow you and stick to my guess that your source code doesn’t
   load the wordpress environment at all.
 *  Thread Starter [hsysgrp](https://wordpress.org/support/users/hsysgrp/)
 * (@hsysgrp)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454666)
 * I am using a twentytwelve child theme. I have pages created in the usual WordPress
   manner using the full-width template. One page uses a template I wrote, custom-
   page_InputMemberID-wpdb.php. This is the code I provided in my first message.
   I have not made any special calls to the WordPress environment other than the
   global $wpdb;
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454759)
 * I have now tried to recreate this on my end and get no error message when calling
   the page. I have created just like you a child theme from TwentyTwelve the template
   file with your above source code and assigned to a page. I get no error message
   at all when calling the page.
 * The only difference between my source code and yours are the lines
 *     ```
       include 'myFuncs.php';
       $link = connect();
       ```
   
 * and
 * `if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error());}`
 * I commented those out in each case.
 * So I now have 2 guesses about your problem:
    Something is happening in myFuncs.
   php that prevents $wpdb from being included. Since you didn’t show the file, 
   I can only guess. Or: Something is wrong with your installation. What that is
   I can’t guess either.
 * Tip 1: try to debug var_dump() to find out if $wpdb is set anywhere in your template.
   
   Tip 2: If the problem turns out to be more complex I would recommend you to address
   it in the platform intended for programmers: [https://wordpress.stackexchange.com](https://wordpress.stackexchange.com)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘$wpdb not loading?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [threadi](https://wordpress.org/support/users/threadi/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/wpdb-not-loading/#post-15454759)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
