473,378 Members | 1,317 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,378 software developers and data experts.

use combobox to insert data to database

27
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 #1
19 9069
Dormilich
8,658 Expert Mod 8TB
add the mentioned indices as name attribute.

ex.
Expand|Select|Wrap|Line Numbers
  1. <select name="from" id="from">
May 6 '09 #2
obtrs
27
thanx for the help DORMILICH so many errors gone by adding name.

But what about
Expand|Select|Wrap|Line Numbers
  1. $d = $_POST['550'];
its not in the list i want this to be inserted that's the rent its same for all.

Error:

Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: 550 in C:\wamp\www\site\booking.php on line 12
  2. Error Cannnot Insert Records!
May 6 '09 #3
Markus
6,050 Expert 4TB
Declare $d's value yourself then.

Expand|Select|Wrap|Line Numbers
  1. $d = 550;
  2.  
May 6 '09 #4
obtrs
27
Declared $d value its not working same error but removing this by removing $d value it also gives error message !cannot insert record
Expand|Select|Wrap|Line Numbers
  1. $query="INSERT INTO trip (from,to,coach_type,fare) values ('$a','$b','$c','$d')";
  2.  

This one

Expand|Select|Wrap|Line Numbers
  1. mysql_query($query) or die ('Error Cannnot Insert Records!');
May 7 '09 #5
obtrs
27
cmon guys im waiting?
May 7 '09 #6
Markus
6,050 Expert 4TB
@obtrs
Patience is a virtue.

add mysql_error() to your die() call. If there's a mysql error, it'll give you the info.

Expand|Select|Wrap|Line Numbers
  1. mysql_query(...) or die(mysql_error());
  2.  
Please note: for lack of a better term, Bytes.com is a privilege, not a right. Until you start paying us cash, you'll have to wait until one of our kind experts takes time out of his day to give you help.

Moderator.
May 7 '09 #7
obtrs
27
Patience is a virtue.
sorry my bad

same 550 fare error even i have declared it in $query

Expand|Select|Wrap|Line Numbers
  1. $query="INSERT INTO trip (from,to,coach_type,fare) values ('$a','$b','$c','$d')";
the last one $d.

Error

Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: 550 in C:\wamp\www\site\booking.php on line 12
  2. You have an error in your SQL syntax; from,to,coach_type,fare)values ('karachi','sukkur','nonac','')' at line 1
database has the same value as shown from,to,coach_type,fare


line 12 in which the error showing:

Expand|Select|Wrap|Line Numbers
  1. $d = $_POST['550'];
May 7 '09 #8
obtrs
27
its showing that the 550 is empty ' ' i have declare it do i have to declare it any where else too?
May 7 '09 #9
Markus
6,050 Expert 4TB
You haven't declared it. You point it to a none-existent index in the POST array.

When I said 'declare its value yourself', I meant assign it's value (550) because you said that was a constant.

Expand|Select|Wrap|Line Numbers
  1. $d = 550;
  2.  
May 7 '09 #10
obtrs
27
i didn't got that???
May 7 '09 #11
obtrs
27
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 Expert Mod 8TB
@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
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 Expert 4TB
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
<moderator note: i accidently overwrote the contents of this post>
May 7 '09 #16
Markus
6,050 Expert 4TB
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
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 Expert 4TB
What error?
May 8 '09 #19
obtrs
27
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
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...
2
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...
3
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...
2
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...
5
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
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
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...
0
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...
3
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 {...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.