0

I have two problems with WordPress.

First I am trying to create a database table with the prefix "ol" but when I add an email into my form, there is no new table created in the databaze. Here is the code:

if ( isset( $_POST['ol-odeslat'] ) ) {
            $name    = sanitize_text_field( $_POST["ol-name"] );
            $email   = sanitize_email( $_POST["ol-email"] );
            require_once('../../../wp-config.php');
            global $wpdb;
            $table_name = $wpdb->prefix . "ol";
            $wpdb->insert( $table_name, array( 'name' => $_POST['ol-name'], 'email' => $_POST['ol-email'] ) );
        } 

Also I am trying to create a table in WordPress admin but I seem to be getting an error that there is an unexpected . (dot) on the line 171. Here is the code:

$sql = "SELECT name,email FROM 'ol' ";
$results = $wpdb->get_results($sql);
if ($results) {
    foreach ($results as $row) {
        echo '<tr>';
        echo '<th>' . $row->name; . '</td>';
        echo '<td>' . $row->email; . '</td>';
        echo '</tr>';
    }
}
2
  • In your first code snippet: are you actually creating the table? Does $wpdb->insert() create the table automatically if it doesn't exist? Commented Nov 19, 2015 at 18:51
  • And in your second snippet: the table name should be $wpdb->prefix . 'ol', shouldn't it? Commented Nov 19, 2015 at 18:51

1 Answer 1

1

About the table creation, you have extra ; Between >>>;<<< in the code below

$sql = "SELECT name,email FROM 'ol' ";
$results = $wpdb->get_results($sql);
if ($results) {
    foreach ($results as $row) {
        echo '<tr>';
        echo '<th>' . $row->name>>>;<<< . '</td>';
        echo '<td>' . $row->email>>>;<<< . '</td>';
        echo '</tr>';
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.