• I’ve got a simple problem, but can’t find the syntax to make it work. I put some conditional code in page.php to force a registration page when a user goes to a page without having first logged in, and it works fine.

    <?php
    if ($thePostID == 2700) {
     global $current_user;
     get_currentuserinfo();
     $user_id = $current_user->ID;
     if ($user_id == 0) include("register.form.php");
    }
    ?>

    Here’s the register.form.php:
    <form name=”registration” method=”post” action=”/wp-content/themes/kbb8/register.form.post.php” >
    <p><label for=”BQ_name”>Name</label><input type=”text” id=”BQ_name” /></p>
    <p><label for=”BQ_email”>E-mail</label> <input type=”text” id=”BQ_email” /></p>
    <div style=”padding-top:4px;” >
    <input type=”button” name=”button” value=”Submit”>
    </div>
    </form>

    Here's the action code:

    <?php
    echo “I was clicked!”;
    echo “<p>”;

    $grf_name = $_POST[‘BQ_name’];
    $grf_email = $_POST[‘BQ_email’];

    $sql = “insert into wp_gRF (gRF_name,gRF_email,gRF_date)
    values (‘$grf_name’,’$grf_email’,NOW())”;

    echo $sql;

    global $wpdb;
    $wpdb->query($sql);

    echo “<p>”;

    echo “Your registration has been submitted!”;
    ?>
    `

    When the button is clicked, the “I was clicked” and the sql statement echo, but then I get the following error: Fatal error: Call to a member function query() on a non-object in /home2/kidsknow/public_html/wp-content/themes/kbb8/welcome.skip.php on line 20

    What am I missing. I know this is basic, but I just haven’t been able to get ahold of the syntax to make this work.

    THANKS!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter skippix

    (@skippix)

    sorry for that awfully formatted post ??

    the form code is this:

    <form name="registration" method="post" action="/wp-content/themes/kbb8/register.form.post.php" >
    <p><label for="BQ_name">Name</label><input type="text" id="BQ_name" /></p>
    <p><label for="BQ_email">E-mail</label> <input type="text" id="BQ_email" /></p>
    <div style="padding-top:4px;" >
    <input type="button" name="button" value="Submit">
    </div>
    </form>

    the processing code is this:

    <?php
    echo "I was clicked!";
    echo "<p>";
    
    $grf_name = $_POST['BQ_name'];
    $grf_email = $_POST['BQ_email'];
    
    $sql = "insert into wp_gRF (gRF_name,gRF_email,gRF_date)
    values ('$grf_name','$grf_email',NOW())";
    
    echo $sql;
    
    global $wpdb;
    $wpdb->query($sql);
    
    echo "<p>";
    
    echo "Your registration has been submitted!";
    ?>

    Thanks again to anyone who can help me straighten this out and make it work!

    Thread Starter skippix

    (@skippix)

    anyone?

    I had the same problem, and I added the file wp-load.php at first,

    for example:

    require_once(‘../../wp-load.php’);

    =)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need help accessing $wpdb’ is closed to new replies.