PHP Select option with 2 values to save into the database

Codes here !

Moderators: egami, macek, gesf

Post Reply
eecanisha
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Jul 16, 2021 12:43 am

Fri Jul 16, 2021 1:00 am

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: Select all

 <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: Select all

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 all

   <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 KiB) Viewed 456 times
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Sun Jul 18, 2021 7:00 am

Where is the database? on the server or PC?

Where is your server side code?
Post Reply