×

Please Login or Register to continue.

5
(5K 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 the database using PHP? 

(90 Points)
in PHP

Share

4 Answers
(9.4K Points)
(edited)
1

I am not getting your point. Where you want to add Combobox. You can add the select option for all subjects 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 them 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. 

 


Comment
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.
osama 05 Sep 2019
Check my other answer.
shakti 05 Sep 2019

(7.3K Points)
(edited)
1

Thank you for asking this question here. I am glad to solve your problem. You can add a 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 the name subject. 

Comment me if the problem occurs.


Comment

(4.3K Points)
(edited)
1

Add Combobox in PHP. 

Try this code. It will help you to add Combobox to 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. 


Comment

(9.4K Points)
(edited)
2

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

combobox in php

 

Follow the steps - 

1. Add this code at the 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 the test database to, your database or add your config file. 

2. Change the 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 tables.

Benefits - 

1. Select data and display it in Combobox.

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


Comment
Check my answer on the new question.
shakti 06 Sep 2019

Related Questions :-

Featured Items:-


Certificate and Marksheet system with verification & Franchise in PHP

$75



Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65




Your Answer

You can post your answer after login..

Live Chat

Hello! How can we assist you today?