• Register
Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the tech & programming Question that you want. Guests Posting are allowed.
+4 votes
30 views

Hello, How to add a Combobox inside the HTML form for subject bio, chemistry, eng, etc..

I wrote every code from technomaster.com site. What I make changes in insert or display code to make it possible to enter Combobox.

My HTML form and table. All data are coming from a MySQL database table using MySQL query and PHP code. 

How can I add Combobox in HTML form and select, display, insert data into database using PHP? 

in PHP by (190 points) 16

4 Answers

+2 votes

I solved your problem . You can add Combobox like this. 

combobox in php

Follw the steps - 

1. Add this code at subject input place.

<?php 

$cser=mysqli_connect("localhost","root","","test") or die("connection failed:".mysqli_error());

$result = mysqli_query($cser,"SELECT pname FROM crud2") or die(mysql_error());

if (mysqli_num_rows($result)!=0)

{

echo 'Product Name : <select name="pname">

      <option value=" " selected="selected">Choose one</option>';

   while($drop_2 = mysqli_fetch_array( $result ))

{

  echo '<option value="'.$drop_2['pname'].'">'.$drop_2['pname'].'</option>';

}

echo '</select>';

}

?> 

2. Now change test database to, your database or add your config file. 

2. Change crud2 table name to your table name. 

3. Change pname to the students' column name. 

In this way, you can add Combobox in your website HTML form using PHP and Mysql database table.

Benefits - 

1. Select data and display in Combobox.

2. Insert data using select name="pname" . Change pname according to your column name.  

by (6.3k points) 3 20 43
edited by
Error with placing Combobox in HTML form using PHP
Check my answer on the new question.
+1 vote

I am not getting your point. Where you want to add Combobox. You can add the select option for all subject like this - 

<select name="name">
  <option value="A">item1</option>
  <option value="B">item2</option>
  <option value="n">item_n</option> 

</select> 

Select all subjects and display in the list. 

<select name="subject">
  <option value="">your PHP code </option>
</select> 

Change the subject variable according to your created variable for the subject. 

by (6.3k points) 3 20 43
edited by
I Want to add a Combobox for subjects.  For Example:- When I Insert new Subject & TotalMarks through another HTML form , the Subjects should come into the combobox.
Check my other answer.
+1 vote

Thank you asking this question here. I am glad to solve your problem. You can add checkbox as the subject input box. 

 echo "<input type='checkbox' name='sujects' value='".$row['subjects']."<br />";

Use select query and display the data inside the checkbox. It will help you insert data using name subject. 

Comment me if the problem occurs.

by (4.4k points) 4 14 44
+1 vote

Add Combobox in PHP. 

Try this code. It will help you to add Combobox in your website HTML form.

include_once('config.php');

$result = mysql_query($mysqli,"SELECT students FROM table_name") or die(mysql_error());

if (mysql_num_rows($result)!=0)

{

echo '<select name="drop_2" id="drop_2">

      <option value=" " selected="selected">Choose one</option>';

   while($drop_2 = mysql_fetch_array( $result ))

{

  echo '<option value="'.$drop_2['students'].'">'.$drop_2['students'].'</option>';

}

echo '</select>';

Change table name and column name. 

by (2.9k points) 1 10 33
...