• ulises2010

    (@ulises2010)


    I need to make a form but I need to fill some fields depending the queries from some fields, and finaly post all to the database.

    For example:

    The user can choose his model of car in the form.

    The first field is a select box with two options: ‘Diesel’ or ‘Fuel’

    Depending the one chosen I ask to the database for all the models in the database (external, no the one from WP) and show other select box with this models….
    do you think it’s possible?

    Thanks

Viewing 1 replies (of 1 total)
  • Yes, it’s possible.

    The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting.

    The benefit is the ability to use all the wpdb classes and functions like get_results, etc so that there’s no need to re-invent the wheel.

    Here’s how:

    $mydb = new wpdb('username','password','database','localhost');
    $rows = $mydb->get_results("select Name from my_table");
    echo "<ul>";
    foreach ($rows as $obj) :
       echo "<li>".$obj->Name."</li>";
    endforeach;
    echo "</ul>";

    Here is the stackexchange link
    https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database

Viewing 1 replies (of 1 total)
  • The topic ‘Query and post to database from a form’ is closed to new replies.