0

I am facing issue to set the Auto drop down in my php form.

while selecting the QC Type, it should automatically select QC Code from MySQL Database. At the moment, i am selecting it manually. Can anyone help.

php Form :

enter image description here

<tr>
            <td align="right"><b>QC Code</b></td>
            <td> 
            <select name="qc_code" >
                 <option>Select a QC Code</option>

                         <?php 
    $get_qc = "select * from qctype";

$run_qc = mysqli_query($con, $get_qc);

while ($row_qctype=mysqli_fetch_array($run_qc)){    


    $qccode_title = $row_qctype['qccode_title'];

echo "<option value='$qccode_title'>$qccode_title</option>";


}

Database : -

enter image description here

4
  • Yes, I am using the following form. Let me know if require more details. <form action="insert_qc.php" method="post" enctype="multipart/form-data"> Commented Oct 20, 2018 at 15:49
  • If you see my image (php form) there is a QC Type and QC Code. Currently, i am selecting QC Code manually. What I want to do is When i select QC Type, it should automatically select QC Code in next drop-down. I belive qctype_id will be helpful in this. Can you please share the code here. Commented Oct 20, 2018 at 15:54
  • Can this help ? I didn't get you ? echo "<option value='$qccode_title'>$qccode_title</option>"; Commented Oct 20, 2018 at 16:01
  • I want to achieve qccode_title automatically in this drop-down if i select qctype_title. Commented Oct 20, 2018 at 16:08

1 Answer 1

1

You should put the title into the value instead. This way the title will be displayed and the value will be submitted.

$qccode_title = $row_qctype['qccode_title'];
$qctype_title = $row_qctype['qctype_title'];
echo "<option value='$qctype_title'>$qccode_title</option>";
Sign up to request clarification or add additional context in comments.

6 Comments

I am getting the value by selecting manually. I have the same code which you have mentioned. This is not allowing me automatic drop-down for qccode_title. The functionality remain same with this
The functionality can't be the same. This has two different fields, your form have the same twice.
I mean, it is working as it was first by your provided code. No changes effected.
You don't need the qc code field anymore. Submit the form and access $_POST['qc_code'] and the code will be there. The value has the value and the element will display the title.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.