php - How to link a textbox value to a database row and then insert it


I have a textbox where it stores in a user's option. The possible options are options 3 all the way to 26, 'True or False' and 'Yes or No'.

<input type="text" name="gridValues" class="gridTxt maxRow" readonly="readonly" />

Now in my database I have a table known as 'Options' which contains an 'OptionId' and 'OptionType' fields. The rows in the table is like this below:

OptionId  OptionType
O1        A-C
O2        A-D
O3        A-E


O24       Yes or No

Now what I want to do if it is possible is that I want options 3-26 and options 'True or False' and 'Yes or No' from the application to link with an 'OptionId' from the database.

For example:

If textbox equals 3 then this equals OptionId 'O1'
If textbox equals 4 then this equals OptionId 'O2'
If textbox equals 5 then this equals OptionId 'O3'


If textbox equals Yes or No then this equals OptionId 'O24'.

I want this to happen because when I INSERT VALUES, I want to INSERT the 'OptionId' in other database tables when I need to.

Is this possible to do and if so does anyone know how to link the textbox value to the 'OptionId' and then INSERT it into a database table known as 'Questions'?




It is not possible to link the textbox with the mysql row.

You will have to send an ajax request with a function attached ononChange event of the textbox to do this.

I am not going to cover the ajax part, but you can do something like this using jquery.

$("#yourtextbox").change(function() {
    var textval = this.value; //get the value
        "yourpage.php", //the page to update the text box based on the values
             'variablename': textval, 
             'action' : 'update' 
         }, //send the values
         function(data) {
             //do something on the success



If I understand correctly your problem then you want to an insert in one table based on another table's value, this can be done with an INSERT SELECT as in

INSERT INTO questions SELECT optionid FROM options WHERE optiontype = $selected_option

People are also looking for solutions to the problem: php read CSV with various amount of delimiters


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.