473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

I have some problems in php code to insert data from drop down list into database

Expand|Select|Wrap|Line Numbers
  1. Hello,
  2. My problem is when I click on submit button after select the name from the dropdown list, the serial no. of the names get inserted into database, but i want to insert the name. I tried a lots but i could not did it.
  3. Plz help me.........
  4. here is code:-
  5. ..............
  6. page1.php
  7.  
  8. <?php
  9. require('dbconnect.php');
  10. $obj_db = new db_connection();
  11. $obj_db->set_dbconnection();
  12. ?>
  13. <form name="frm1" action="process.php" method="post">
  14. <table border="0">
  15. <tr>
  16.     <td>Author</td>
  17.     <td><select name="author" id="author">
  18.         <option value="NA">-SELECT-</option>
  19.         <?php
  20.             $s_pref = "SELECT author_id AS value,author_name AS text FROM author_table  ORDER BY author_name";
  21.  
  22.             $res=mysql_query($s_pref);
  23.             while($row=mysql_fetch_object($res)):
  24.                 $authorId=$row->value;                
  25.                 $authorName=$row->text;                
  26.             ?>
  27.             <option value="<?php echo $authorId; ?>"><?php echo $authorName; ?> </option>
  28.             <?php            
  29.             endwhile;
  30.             ?>    
  31.         </select></td>        
  32.         <td>Publication</td>
  33.         <td><select name="publication" id="publication">
  34.                    <option value="NA">-Select-</option>
  35.                    <?php
  36.             $s_pref1 = "SELECT publication_id AS value,publicationname AS text FROM publication  ORDER BY publicationname";
  37.  
  38.             $res1=mysql_query($s_pref1);
  39.             while($row=mysql_fetch_object($res1)):
  40.                 $publicationId=$row->value;
  41.                 $publicationName=$row->text;
  42.             ?>
  43.             <option value="<?php echo $publicationId; ?>"><?php echo $publicationName; ?> </option>
  44.             <?php
  45.             endwhile;
  46.             ?>    
  47.         </select></td>
  48.  
  49.         </td>
  50.         <tr>
  51.             <td><input type="submit" value="SUBMIT"/></td>
  52.         </tr>
  53.         </table>
  54.         </form>
  55. </tr>
  56.  
  57. ..................................................................
  58. process.php
  59.  
  60. <?php
  61. session_start();
  62. //** DB connection **//
  63. require('dbconnect.php');
  64. $obj_db = new db_connection();
  65. $obj_db->set_dbconnection();
  66. ?>
  67. <?php
  68.    $Auth=$_POST['author'];
  69.    $pub=$_POST['publication'];
  70.    $query="INSERT INTO     master(author,name_of_publication) VALUES('$Auth','$pub')";
  71.    $res=mysql_query($query);
  72.    if($res)
  73.        echo "success";
  74. else 
  75.    echo "Not successfull";    
  76. ?>
  77. ................................................................
  78. dbconnect.php
  79. <?php
  80. class db_connection{
  81.  
  82.     function set_dbconnection()
  83.     {
  84.         //Set db connection
  85.         define('DB_USER','root');
  86.         define('DB_PASSWORD','');
  87.         define('DB_HOST','localhost');        
  88.  
  89.  
  90.  
  91.         /*define('DB_USER','rgcepuser');
  92.         define('DB_PASSWORD','Rg#m~18febcep');
  93.         define('DB_HOST','localhost');*/
  94.         //make a connection
  95.  
  96.         $db_connect=@mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("NOT Connected");
  97.         $dblink=@mysql_select_db('library_management',$db_connect);
  98.  
  99.         if(!$dblink):
  100.             echo 'ERROR!!!',@mysql_error();
  101.             exit;
  102.         endif;
  103.  
  104.     }
  105. }
  106. ?>
  107. .............................................................
  108. DATA BASE
  109.  
  110. -- phpMyAdmin SQL Dump
  111. -- version 2.10.0.2
  112. -- http://www.phpmyadmin.net
  113. -- 
  114. -- Host: localhost
  115. -- Generation Time: Sep 21, 2014 at 04:11 AM
  116. -- Server version: 5.0.37
  117. -- PHP Version: 5.2.1
  118.  
  119. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  120.  
  121. -- 
  122. -- Database: `library_management`
  123. -- 
  124.  
  125. -- --------------------------------------------------------
  126.  
  127. -- 
  128. -- Table structure for table `author_table`
  129. -- 
  130.  
  131. CREATE TABLE `author_table` (
  132.   `slno` int(5) NOT NULL auto_increment,
  133.   `author_id` int(6) default NULL,
  134.   `author_name` varchar(50) collate latin1_general_ci NOT NULL,
  135.   UNIQUE KEY `slno` (`slno`),
  136.   UNIQUE KEY `author_id` (`author_id`)
  137. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ;
  138.  
  139. -- 
  140. -- Dumping data for table `author_table`
  141. -- 
  142.  
  143. INSERT INTO `author_table` VALUES (1, 1, 'Shiv  Khera');
  144. INSERT INTO `author_table` VALUES (2, 2, 'Ramananda');
  145. INSERT INTO `author_table` VALUES (3, 3, 'Rajib Bhatia');
  146. INSERT INTO `author_table` VALUES (4, 4, 'Krishna Kant Bhatia');
  147. INSERT INTO `author_table` VALUES (5, 5, 'Minakumary Pandit');
  148. INSERT INTO `author_table` VALUES (6, 6, 'Mc Gall');
  149. INSERT INTO `author_table` VALUES (7, 7, 'Kabira Alam Chaudhury');
  150. INSERT INTO `author_table` VALUES (8, 8, 'Mina Kumary Bala');
  151.  
  152. -- --------------------------------------------------------
  153.  
  154. -- 
  155. -- Table structure for table `master`
  156. -- 
  157.  
  158. CREATE TABLE `master` (
  159.   `slno` bigint(10) NOT NULL auto_increment,
  160.   `ISBN` varchar(70) collate latin1_general_ci default NULL,
  161.   `book_name` varchar(70) collate latin1_general_ci default NULL,
  162.   `author` varchar(50) collate latin1_general_ci default NULL,
  163.   `name_of_publication` varchar(60) collate latin1_general_ci default NULL,
  164.   `date` text collate latin1_general_ci,
  165.   `price` decimal(7,2) default NULL,
  166.   UNIQUE KEY `slno` (`slno`,`ISBN`)
  167. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=21 ;
  168.  
  169. -- 
  170. -- Dumping data for table `master`
  171. -- 
  172.  
  173. INSERT INTO `master` VALUES (1, NULL, NULL, '7', '', NULL, NULL);
  174. INSERT INTO `master` VALUES (2, NULL, NULL, '3', '', NULL, NULL);
  175. INSERT INTO `master` VALUES (3, NULL, NULL, '7', '', NULL, NULL);
  176. INSERT INTO `master` VALUES (4, NULL, NULL, '1', '', NULL, NULL);
  177. INSERT INTO `master` VALUES (5, NULL, NULL, '1', '', NULL, NULL);
  178. INSERT INTO `master` VALUES (6, NULL, NULL, '1', '', NULL, NULL);
  179. INSERT INTO `master` VALUES (7, NULL, NULL, '7', '', NULL, NULL);
  180. INSERT INTO `master` VALUES (8, NULL, NULL, '', '', NULL, NULL);
  181. INSERT INTO `master` VALUES (9, NULL, NULL, '', '', NULL, NULL);
  182. INSERT INTO `master` VALUES (10, NULL, NULL, '', '', NULL, NULL);
  183. INSERT INTO `master` VALUES (11, NULL, NULL, '6', '', NULL, NULL);
  184. INSERT INTO `master` VALUES (12, NULL, NULL, '6', '', NULL, NULL);
  185. INSERT INTO `master` VALUES (13, NULL, NULL, '', '', NULL, NULL);
  186. INSERT INTO `master` VALUES (14, NULL, NULL, '', '', NULL, NULL);
  187. INSERT INTO `master` VALUES (15, NULL, NULL, '4', '', NULL, NULL);
  188. INSERT INTO `master` VALUES (16, NULL, NULL, '4', '1', NULL, NULL);
  189. INSERT INTO `master` VALUES (17, NULL, NULL, '', '', NULL, NULL);
  190. INSERT INTO `master` VALUES (18, NULL, NULL, '', '', NULL, NULL);
  191. INSERT INTO `master` VALUES (19, NULL, NULL, '4', '2', NULL, NULL);
  192. INSERT INTO `master` VALUES (20, NULL, NULL, '4', '2', NULL, NULL);
  193.  
  194. -- --------------------------------------------------------
  195.  
  196. -- 
  197. -- Table structure for table `publication`
  198. -- 
  199.  
  200. CREATE TABLE `publication` (
  201.   `slno` int(8) NOT NULL auto_increment,
  202.   `publication_id` int(6) default NULL,
  203.   `publicationName` varchar(60) collate latin1_general_ci NOT NULL,
  204.   UNIQUE KEY `slno` (`slno`),
  205.   UNIQUE KEY `publication_id` (`publication_id`)
  206. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;
  207.  
  208. -- 
  209. -- Dumping data for table `publication`
  210. -- 
  211.  
  212. INSERT INTO `publication` VALUES (1, 1, 'BPB PUBLICATION');
  213. INSERT INTO `publication` VALUES (2, 2, 'ASSAM TRIVAL PUBLICATION');
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
Sep 21 '14 #1
0 1166

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
2
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I am new in asp.net, i encounter some problems in using drop down list and datagrid. I have manage to bind the data into datagrid but i wanted to bind the data into the datagrid accroding...
2
by: Ren | last post by:
Hi all, I am a bit new to PHP and SQL so this may seem like a dumb question. I have already created a drop down list as part of a form which is automatically populated with values taken from a...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
0
by: Derty | last post by:
Have an issue with a simple drop down list that I need to filter results of a database table and page display. I can get the drop down list to populate correctly but can't make the page databound...
3
by: Brad Isaacs | last post by:
ASP.NET 2.0 / SQL Server 2000 db / Visual Basic Code behind On my .aspx page I have added an SQL Datasource that contains the SQL query to retrieve the list for my Drop Down List Box. Using...
1
by: jacbyrd | last post by:
I have created a user control that is a drop down list that pulls from my database. I then drop that control into a detailsview control on an insert item template. When I run the insert command,...
9
by: prokopis | last post by:
am new in c# and i have some problems that o need some help i have t text box that when i type the characters i want a drop down list to be appeard under the text box sorted according the characters...
1
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.