473,566 Members | 2,812 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 #1
19 9095
Dormilich
8,658 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Expert
Declare $d's value yourself then.

Expand|Select|Wrap|Line Numbers
  1. $d = 550;
  2.  
May 6 '09 #4
obtrs
27 New Member
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 New Member
cmon guys im waiting?
May 7 '09 #6
Markus
6,050 Recognized Expert Expert
@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 New Member
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_t ype,fare


line 12 in which the error showing:

Expand|Select|Wrap|Line Numbers
  1. $d = $_POST['550'];
May 7 '09 #8
obtrs
27 New Member
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 Recognized Expert Expert
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

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

Similar topics

3
1974
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
12870
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...
3
2115
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...
2
1783
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. ...
5
24992
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
5512
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
2063
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...
0
2000
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,...
3
14360
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
6062
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...
0
7666
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...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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...
0
7951
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...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.