Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using wpdb to insert not working

Posted on 2015-02-16
6
Medium Priority
?
302 Views
Last Modified: 2015-02-24
See attached.

This is a simple test program to try to insert a row into a table using wpdb class. Does not work. Nothing inserted.

Image shows table structure in database.

What's wrong?

Thanks
test-dbinsert.php
captcha-str.jpg
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40613050
What happens if you turn on WP_DEBUG?  What errors are reported.
0
 

Author Comment

by:Richard Korts
ID: 40613210
Note that the program is NOT a WordPress program; it's php OUTSIDE of WordPress.

I put in the debug; probably didn't do it right. Here is the WHOLE program

<?php
$code=rand(1000,9999);
$skey = intval($_GET['skey']);
require( 'wp-load.php' );
define('WP-DEBUG', true);
global $wpdb;
$wpdb->insert(
      'captcha',
      array(
            'skey' => $skey,
            'code' => $code
      ),
      array(
            '%d',
            '%d'
      )
);
?>

Ran it again; does nothing. No debug statements, nothing.

Thanks
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40613231
I put in the debug; probably didn't do it right.

Yeah, nope.  WP_DEBUG goes in wp-config.php so it needs to run inside.

Why use $wpdb if you are running completely outside the framework? For database authentication?
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

Author Comment

by:Richard Korts
ID: 40613242
Jason,

Because I tried the normal connect to the database with normal SQL & it failed too.

I echoed the Insert statement, (normal SQL), I copied it & used it in phpMyadmin & it inserted fine.

FYI, this is just my Plan B way of working since $_SESSION variables do not work, even outside WordPress. I have a whole nother question on that in the php category, No Expert yet has solved that either.
0
 

Author Comment

by:Richard Korts
ID: 40613256
Jason,

I envision a solution to this where I put in a NEW database totally devoted just to this ONE process, keeps all WordPress influences out of it & do it that way.

What a pain but I have spent the ENTIRE day on this ONE problem to no avail.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 40613476
Because I tried the normal connect to the database with normal SQL & it failed too...Keeps all WordPress influences out of it & do it that way

There's absolutely no reason why a normal PHP call to mysqli() with correct authentication details wouldn't work.  Using $wpdb should also work assuming your load works properly.

For error checking, do this:

require( 'wp-load.php' );
global $wpdb;
$wpdb->show_errors();
$wpdb->insert(
      'captcha',
      array(
            'skey' => $skey,
            'code' => $code
      ),
      array(
            '%d',
            '%d'
      )
);

Open in new window


and hopefully we get something out of it.
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are looking for plug-ins to add functions to your WordPress small business web site, take some time to read though this comprehensive list.  These are all the plugins I use for my customers WordPress web sites, as well as my own.  Be sure to …
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question