473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use combobox to insert data to database

27 New Member
I have some code for drop down its not working it gives the errors every thing looks fine to me help me out.


Errors

Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: from in C:\wamp\www\site\booking.php on line 6
  2.  
  3. Notice: Undefined index: to in C:\wamp\www\site\booking.php on line 8
  4.  
  5. Notice: Undefined index: couch in C:\wamp\www\site\booking.php on line 10
  6.  
  7. Notice: Undefined index: 550 in C:\wamp\www\site\booking.php on line 12
  8. Error Cannnot Insert Records! 




PHP CODE:


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. if(isset($_POST['submit']))
  5. {
  6. $a = $_POST['from'];
  7.  
  8. $b = $_POST['to'];
  9.  
  10. $c = $_POST['couch'];
  11.  
  12. $d = $_POST['550'];
  13.  
  14.  
  15.  
  16. mysql_connect("localhost", "root", "password") or die ('Error'.mysql_error());
  17.  
  18. mysql_select_db("online_bus_project");
  19.  
  20.  
  21. $query="INSERT INTO trip (from,to,coach_type,fare) values ('$a','$b','$c')";
  22.  
  23.  
  24.  
  25. mysql_query($query) or die ('Error Cannnot Insert Records!');
  26.  
  27. }
  28.  
  29. ?>


HTML CODE:


Expand|Select|Wrap|Line Numbers
  1. <div id="status"><form name="status" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  2.               <br>
  3.   <br>
  4.   <br>
  5.   <table class="note" width="90%" align="center" border="0" cellpadding="2" cellspacing="2">
  6.     <tbody><tr> 
  7.       <td colspan="4" class="header" width="100%" align="center"><font size="4" color="royalblue" face="Verdana, Arial, Helvetica, sans-serif"><b class="heading"><span class="header"><font color="#336699">Welcome 
  8.         To Online B<span class="heading"><span class="heading">us Reservation</span></span></font></span><br>
  9.         </b><font size="2" color="#ff0000">Please Select your date of departure and destination to proceed ahead with the booking.</font><font size="2" color="#000000"> 
  10.         </font></font></td>
  11.     </tr>
  12.     <tr> 
  13.       <td colspan="4" width="100%">&nbsp;</td>
  14.     </tr>
  15.  
  16.  
  17.  
  18. <tr> 
  19.  
  20.  
  21.   <td font="" face="Verdana, Arial, Helvetica, sans-serif" size="2" width="25%" align="left" height="30"> 
  22. <center>
  23.  
  24.    <br /><center> <strong>From:</strong>            
  25.     *****<select id="from">
  26.  
  27.     <option value = "karachi">Karachi</option>
  28.  
  29.     <option value = "sukkur">Sukkur</option>
  30.  
  31.     </select>
  32.      <center><br />
  33.      <strong>To:</strong>**********
  34.      <select id="to"></center>
  35.  
  36.     <option value = "sukkur">Sukkur</option>
  37.  
  38.     <option value = "karachi">Karachi</option>
  39.  </select>
  40.  
  41.      <center><br /><strong>Couch:***</strong>
  42.      <select id="couch"></center>
  43.  
  44.     <option value = "nonac">NonAC</option>
  45.  
  46.     <option value = "ac">AC</option>
  47.  </select>
  48.  
  49.     </select>
  50.  
  51.  
  52.  
  53.     <!--
  54.     <tr> 
  55.       <td width="100%" colspan=4>&nbsp;</td>
  56.     </tr>
  57.     -->
  58.     <tr> 
  59.       <td colspan="4" width="100%"><hr width="95%" align="left" noshade="noshade"></td>
  60.     </tr>
  61.  
  62.  
  63.    <tr> 
  64.       <td colspan="4" width="100%" align="center"> 
  65.  
  66.  
  67.     <input type="submit" value="Submit" name="submit"> 
  68.     </form>
May 6 '09
19 9105
obtrs
27 New Member
i didn't got that???
May 7 '09 #11
obtrs
27 New Member
u mean that i have to use the value instead of variable $d i have to put direct 550 in values?
May 7 '09 #12
Dormilich
8,658 Recognized Expert Moderator Expert
@obtrs
you don't have to put it directly in the SQL, but it's a good idea, esp. when the value doesn't change.
May 7 '09 #13
obtrs
27 New Member
its not working either this way or that is there any thing wrong with the code?


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. if(isset($_POST['submit']))
  5. {
  6. $a = $_POST['from'];
  7.  
  8. $b = $_POST['to'];
  9.  
  10. $c = $_POST['couch'];
  11.  
  12. $d = $_POST['550'];
  13.  
  14.  
  15.  
  16. mysql_connect("localhost", "root", "autodeskmaya") or die ('Error'.mysql_error());
  17.  
  18. mysql_select_db("online_bus_project");
  19.  
  20.  
  21. $query="INSERT INTO trip (from,to,coach_type,fare) values ('$a','$b','$c','$d')";
  22.  
  23.  
  24.  
  25. mysql_query($query) or die (mysql_error());
  26.  
  27. }
  28.  
  29. ?>
  30.  
  31.  
  32.  
  33.  
  34. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35. <html xmlns="http://www.w3.org/1999/xhtml">
  36. <head>
  37. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  38. <title>Untitled Document</title>
  39. <link href="obrs.css" rel="stylesheet" type="text/css" />
  40. <!--[if IE 5]>
  41. <style type="text/css"> 
  42. /* place css box model fixes for IE 5* in this conditional comment */
  43. .twoColFixRtHdr #sidebar1 { width: 220px; }
  44. </style>
  45. <![endif]--><!--[if IE]>
  46. <style type="text/css"> 
  47. /* place css fixes for all versions of IE in this conditional comment */
  48. .twoColFixRtHdr #sidebar1 { padding-top: 30px; }
  49. .twoColFixRtHdr #mainContent { zoom: 1; }
  50. /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
  51. </style>
  52. <![endif]-->
  53. <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
  54. <style type="text/css">
  55. <!--
  56. .style1 {
  57.     color: #FFFF00;
  58.     font-weight: bold;
  59. }
  60. .style2 {
  61.     color: #FFFF66;
  62.     font-weight: bold;
  63. }
  64. #apDiv1 {
  65.     position:absolute;
  66.     left:35px;
  67.     top:168px;
  68.     width:621px;
  69.     height:362px;
  70.     z-index:1;
  71. }
  72. -->
  73. </style>
  74.  
  75.  
  76. </head>
  77.  
  78. <body class="twoColFixRtHdr">
  79. <div id="container">
  80.   <div id="header">
  81.     <!-- end #header -->
  82.     <img src="images/header" alt="OBTRS: Header" /></div>
  83.   <div id="sidebar1">
  84.     <!-- end #sidebar1 -->
  85.     <img src="images/sidebar_slideshow" alt="" />
  86.     <div id="blogarea">
  87.       <p class="style2">Casual Dining Restaurants</p>
  88.       <p><br />
  89.         Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p>
  90.       <p><br />
  91.           <span class="style1">Convenience Stores</span></p>
  92.       <p><br />
  93.         Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be &quot;fast&quot; to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong &quot;team spirit&quot; that provides the customers what they are looking for as they travel.</p>
  94.     </div>
  95.   </div>
  96.   <div id="mainContent">
  97.     <div id="nav">
  98.       <script type="text/javascript">
  99. AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code
  100.     </script>
  101.       <noscript>
  102.       <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30">
  103.         <param name="movie" value="images/nav_bar2.swf">
  104.         <param name="quality" value="high" />
  105.         <embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed>
  106.       </object>
  107.       </noscript>
  108.     </div>
  109.  
  110.     <div id="status"><form name="status" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  111.               <br>
  112.   <br>
  113.   <br>
  114.  
  115.  
  116.  
  117.   <table class="note" width="90%" align="center" border="0" cellpadding="2" cellspacing="2">
  118.     <tbody><tr> 
  119.       <td colspan="4" class="header" width="100%" align="center"><font size="4" color="royalblue" face="Verdana, Arial, Helvetica, sans-serif"><b class="heading"><span class="header"><font color="#336699">Welcome 
  120.         To Online B<span class="heading"><span class="heading">us Reservation</span></span></font></span><br>
  121.         </b><font size="2" color="#ff0000">Please Select your date of departure and destination to proceed ahead with the booking.</font><font size="2" color="#000000"> 
  122.         </font></font></td>
  123.     </tr>
  124.     <tr> 
  125.       <td colspan="4" width="100%">&nbsp;</td>
  126.     </tr>
  127.  
  128.  
  129.  
  130. <tr> 
  131.  
  132.  
  133.   <td font="" face="Verdana, Arial, Helvetica, sans-serif" size="2" width="25%" align="left" height="30"> 
  134. <center>
  135.  
  136.    <br /><center> <strong>From:</strong>            
  137.     *****<select name="from" id="from">
  138.  
  139.     <option value = "karachi">Karachi</option>
  140.  
  141.     <option value = "sukkur">Sukkur</option>
  142.  
  143.     </select>
  144.      <center><br />
  145.      <strong>To:</strong>**********
  146.      <select name="to" id="to"></center>
  147.  
  148.     <option value = "sukkur">Sukkur</option>
  149.  
  150.     <option value = "karachi">Karachi</option>
  151.  </select>
  152.  
  153.      <center><br /><strong>Couch:***</strong>
  154.      <select name="couch" id="couch"></center>
  155.  
  156.     <option value = "nonac">NonAC</option>
  157.  
  158.     <option value = "ac">AC</option>
  159.  </select>
  160.  
  161.     </select>
  162.  
  163.  
  164.  
  165.     <!--
  166.     <tr> 
  167.       <td width="100%" colspan=4>&nbsp;</td>
  168.     </tr>
  169.     -->
  170.     <tr> 
  171.       <td colspan="4" width="100%"><hr width="95%" align="left" noshade="noshade"></td>
  172.     </tr>
  173.  
  174.  
  175.    <tr> 
  176.       <td colspan="4" width="100%" align="center"> 
  177.  
  178.  
  179.     <input type="submit" value="Submit" name="submit"> 
  180.     </form>
  181.       </td>
  182.     </tr>
  183.  
  184.     <tr> 
  185.       <td colspan="4" align="center">&nbsp;</td>
  186.     </tr>
  187.  
  188. <!--
  189.     <tr> 
  190.       <td width="100%" align="center" colspan="4"> 
  191.         <div align="left" class="note"> 
  192.           <hr noshade width="95%" align="left">
  193.           <font face="Verdana, Arial, Helvetica, sans-serif" size="2"><font color="#000000"><br>
  194.           Note :</font></font> <span class="note">Please fill in your departure 
  195.           and destination stations, number of seats required and the prefered 
  196.           date of your journey in this page and click on "Check Status" </span></div>
  197.       </td>
  198.     </tr>
  199.     -->
  200.  
  201.   </tbody></table>
  202.  
  203.     </form></td>
  204.     </tr>
  205.     </tbody></table></div>
  206.     <div id="features"></div>
  207.     <!-- end #mainContent -->
  208.   </div>
  209.   <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
  210.   <br class="clearfloat" />
  211.   <div id="footer">
  212.     <p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms &amp; Conditions</a> | <a href="contactus.html">Contact us</a></p>
  213.     <p> 2009 Copyright - Shah Abdul Latif University Khairpur</p>
  214.     <!-- end #footer -->
  215.   </div>
  216.   <!-- end #container -->
  217. </div>
  218.  
  219. </body>
  220. </html>
  221.  
May 7 '09 #14
Markus
6,050 Recognized Expert Expert
Reread what I posted. You're still trying to assign $d to a variable that doesn't exist!

Change $d = $_POST['550'] to just $d = 550
May 7 '09 #15
obtrs
27 New Member
<moderator note: i accidently overwrote the contents of this post>
May 7 '09 #16
Markus
6,050 Recognized Expert Expert
You're trying to insert into 4 columns but only providing 3 values. Try something like
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `table` ('from, to, coach_type, fare) VALUES ('sukkur', 'karachi', 'nonac')
  2.  
May 7 '09 #17
obtrs
27 New Member
tried every thing just stuck with this error i have deleted some unnecessary things now i have this code with same error:

PHP CODE:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. if(isset($_POST['submit']))
  5. {
  6. $a = $_POST['from'];
  7.  
  8. $b = $_POST['to'];
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. mysql_connect("localhost", "root", "password") or die ('Error'.mysql_error());
  17.  
  18. mysql_select_db("online_bus_project");
  19.  
  20.  
  21. $query="INSERT INTO trip (from,to) values ('$a','$b')";
  22.  
  23.  
  24.  
  25. mysql_query($query) or die (mysql_error());
  26.  
  27. }
  28.  
  29. ?>

HTML CODE:
Expand|Select|Wrap|Line Numbers
  1. <form name="status" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  2.               <br>
  3.   <br>
  4.   <br>
  5.  
  6.  
  7.  
  8.   <table class="note" width="90%" align="center" border="0" cellpadding="2" cellspacing="2">
  9.     <tbody><tr> 
  10.       <td colspan="4" class="header" width="100%" align="center"><font size="4" color="royalblue" face="Verdana, Arial, Helvetica, sans-serif"><b class="heading"><span class="header"><font color="#336699">Welcome 
  11.         To Online B<span class="heading"><span class="heading">us Reservation</span></span></font></span><br>
  12.         </b><font size="2" color="#ff0000">Please Select your date of departure and destination to proceed ahead with the booking.</font><font size="2" color="#000000"> 
  13.         </font></font></td>
  14.     </tr>
  15.     <tr> 
  16.       <td colspan="4" width="100%">&nbsp;</td>
  17.     </tr>
  18.  
  19.  
  20.  
  21. <tr> 
  22.  
  23.  
  24.   <td font="" face="Verdana, Arial, Helvetica, sans-serif" size="2" width="25%" align="left" height="30"> 
  25. <center>
  26.  
  27.    <br /><center> <strong>From:</strong>            
  28.     *****<select name="from" id="from">
  29.  
  30.     <option value = "karachi">Karachi</option>
  31.  
  32.     <option value = "sukkur">Sukkur</option>
  33.  
  34.     </select>
  35.      <center><br />
  36.      <strong>To:</strong>**********
  37.      <select name="to" id="to"></center>
  38.  
  39.     <option value = "sukkur">Sukkur</option>
  40.  
  41.     <option value = "karachi">Karachi</option>
  42.  </select>
May 8 '09 #18
Markus
6,050 Recognized Expert Expert
What error?
May 8 '09 #19
obtrs
27 New Member
Marcus thanx for the help buddy u helped alot i really appreciate every time i have posted u replied man thanx.

its working now with this direct way.


made another php and database for testing purpose working.
Expand|Select|Wrap|Line Numbers
  1. mysql_query("INSERT INTO test2 (name, dob, gender, country) VALUES ('$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[country]')"); 
  2.  
May 8 '09 #20

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

Similar topics

3
1986
by: Paul Fairless | last post by:
Customers table - contains Columns: CustID, Surname, Forename, TtlID Titles table - contains Columns: TtlID, Title TtlID is a Foreign Key in the Customers table. I have a Form frmCustomers which contains a ComboBox to select the Customer's Title. The ComboBox is populated from the database
2
12881
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the...
3
2121
by: Support | last post by:
Hi All, I am working in VB.NET. I have a data bound control (combobox) which I want to fill with a certain field of my table from database ( SQL as backend). The issue is, I want these values to fill the combo at the index specified by me, ie, not the usual 0,1,2.... by default. Also, not dataset, but I am using dataReader. Can anyone send me the sample code for the same? Thanks for your help.
2
1787
by: SKarnis | last post by:
We are trying to rebuild a current Access 2002 (XP) mdb program to VB.NET with a SQL database - we are having problems with a suitable combobox. There are many threads discussing multiple column comboboxes in .NET. We are having success with the multiple columns similar to the combobox from Access 2002 (XP). Our biggest problem is speed. In a form in Access 2002, our combobox is able to load data in a table in separate Access database...
5
25026
by: Steve B. | last post by:
Without adding whitespace to the ComboBox datasource is there a way I can add a blank entry or, a reset entry, to the ComboBox dropdown Thanks Steve
0
5520
by: reloader | last post by:
Hi all, I would like to ask you about combobox refershing. My code is: <title>none</title> <body> <table border="1" width="100%" cellspacing="0" cellpadding="2"> <% dim m_DB
1
2067
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on a listbox.selecteditem. When a different item is selected in the listbox, all the fields are repopulated with the correct data. I have 1 combobox which is acting weird.
0
2015
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes, but I'm running into problems with my DropDownLists (ComboBoxes).
3
14368
by: Przemek M. Zawada | last post by:
Dear Group, I'm developing sample window form, using DataGridView control, which is filled with data through BindingSource, which is based on type of object, as follow: public sampleClass { public int itemNumber; public string itemName;
5
6065
by: sivadhanekula | last post by:
Hi everyone.. I want to insert a combobox with the list of test names of a database, but the testname contains 15000+ data, and I cant type all the data. so can any one help me in writing an SQL statement, so that if I give that statement it will automatically swaps the table names to the combobox. P.S I know the SQL statement but I dono where to give that SQL statement in combobox explanation with program will be verymuch helpfull for...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.