WordPress.org

Ready to get started?Download WordPress

Forums

Help me with inserting info into Databse (5 posts)

  1. mirrorside
    Member
    Posted 3 years ago #

    Hello.
    (The table name is not the real one)

    I am trying to get a vote-system for comments.
    In the following mysql-query the comment_ID is added to the database.
    This is achieved with $commentid = get_comment_ID();

    The comment_author and user_login fields are blank and are not being filled with information.

    This is how I try to catch these informations:
    comment_author

    $commentauthor = get_comment_author();
    $commentauthor = $_POST['comment_author'];

    user_login

    global $current_user;
    get_currentuserinfo();
    $current_user = $current_user->user_login;
    $current_user = $_POST['userlogin'];

    This is the insert query.

    $wpdb->query("INSERT INTO 1111_voting (comment_ID, comment_author, user_login) VALUES ($commentid, '$commentauthor', '$userlogin')");

    Thank you in advance for problem-solving.

  2. tehjrow
    Member
    Posted 3 years ago #

    This page helped me. Even though the table is in the wordpress database it's not a part of wordpress so you have to make a new instance of $wpdb.

    http://wordpress.org/support/topic/pros-and-cons-of-adding-tables-to-the-wp-db?replies=8#post-1201613

  3. tehjrow
    Member
    Posted 3 years ago #

    Specifically the part labeled "Access new tables in the WP DB"

  4. Why not just use the commentmeta table to store the data?

  5. mirrorside
    Member
    Posted 3 years ago #

    This functions regarding user_login

    global $current_user;
    get_currentuserinfo();
    $userlogin = $current_user->user_login;

    Now I just need the comment_author insert.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.