Question:

How can you get a selected value from HTML form select to MySQL database?

by  |  earlier

0 LIKES UnLike

Hey,

I'm working on the last bit of an ongoing project I've been working on for the past few months and this is something I've never actually had the experience in working with. For the record I don't code PHP.

In short: I have a preexisting html/php form which gets the values for all information entered into the fields and submits them to a database. Currently all of the fields are Textfields, Textareas and Image Uploads, and now I'm in need of adding an HTML dropdown/select box with 4 options - north, south, east, and west.

Creating the html box is easy but how to i get the value that is selected to be the one that is sent to the database. And what fields do I need to create in the database table to coincide with the select form.

Note* This isn't a dynamic dropdown list; I don't need to get the values from the database just submit them to the database.

 Tags:

   Report

1 ANSWERS


  1. Let's setup your form:

    <form action="form_post.php" method="post">

    <select name="the_variable_name">

    <option value='North'>North</option>

    <option value='South'>South</option>

    <option value='East'>East</option>

    <option value='West'>West</option>

    </select>

    </form>

    ---------- form_post.php --------

    <?php

    // This will display the select box value

    echo $_POST['the_variable_name'];

    ?>

    How to enter it into MySQL: http://www.tizag.com/mysqlTutorial/mysql...

    Take care,

    Chad

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.