PHP Select option with 2 values to save into the database

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Hi guys, I use the posting form to submit the data but inside I am trying to add on the select option and try to set 2 values. Where in the option I assign value as a string and the value output in code number. At the same time when the user chooses it shows the string beside the selection. I make it work for this but when I try to save it or try to read the data 2 be separate it into the database. It only shows the string value.

So how do I actually save 2 different values into the database?


Below is code work for display the string beside the selection. I use javascript to read the value and display for this and when i try to save it only save the string

Code:
 <div class="container mb-2">
                                        <div class="row g-2 align-items-center">
                                            <div class="col-6">
                                                <select class="form-control" id="credit_code" name="credit_code">
                                                    <option selected disabled value="">Credit Account No >></option>
                                                    <option value="CIMB">3020</option>
                                                    <option value="Electronics/Gadgets">3335</option>
                                                    <option value="Motor Vehicles">3330</option>
                                                </select>
                                                <span style="color:red; font-size:15px;"><?= $errors['credit_err'] ?></span>
                                            </div>
                                            <div class="col-6">
                                                <span class="form-text" style="font-size:16px;">
                                                    <input class="form-control-plaintext" type="text" id="credit_name" name="credit_name" onclick="credit_value()" readonly>
                                                </span>
                                            </div>
                                        </div>
                                    </div>

Javascript to display string beside

Code:
var select2 = document.getElementById('credit_code');
        var input2 = document.getElementById('credit_name');
        select2.onchange = function() {
            input2.value = select2.value;
        }

I try to improvise the code to be like this but when I did this I don't know how to show it string beside and save the data to the database

Code:
   <select class="form-control" id="credit_code" name="credit_code">
           <option selected disabled value="">Credit Account No >></option>
           <option value="3020" data-credit_name='"CIMB"  data-credit_code=3020>3020</option>
   </select>


Can anybody help me with my code? I don't know how to save the separate data to the 2 different columns in the database and when the selection option select it should display a string beside it.
 

Attachments

  • 1.jpg
    1.jpg
    23 KB · Views: 1,370
Where is the database? on the server or PC?

Where is your server side code?
 
Back
Top