I am trying to create an add command in my system............i know I wrote the write codes but it is still not working.......here is my the story... I am supposed to create a reservation form that will add to the database and will display your reservation has been saved, but it is not working.....it keeps on saying "undefined index on reservation_insert.php on line 14" can anyone help me in correcting my codes.......I have been reading tutorials but nothing is good enough....here is my codes...

reservation.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Partas Bus</title>
<style type="text/css">
body {
	background-color: #CEF7F5;
}
</style>
<link href="css/reservationlayout.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="wrapper">
  <div id="logo"></div>
  <div id="navigation"><a href="home.php">Home</a> | <a href="reservation.php">Reservation</a> | <a href="trips.php"> Trips</a> | <a href="contactus.php">Contact Us</a> | <a href="ticket.php"> Ticket</a></div>
  <div id="headerImg"></div>
  <div id="bodyArea"><h1>Reservation</h1>
  
 
<form method="post" action="reservation_insert.php" >
									


<br />

Name:                                   <input type="text" class="field small-field" name='search' /><br /><br />

Contact No:<input type="text" class="field small-field" name='search' /><br /><br />
                                Email Add:
                                <input type="text" class="field small-field" name='search' /><br /><br />
                                Origin
      :
      <select>
   <option>-SELECT-</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select><br /><br />
                               Destination:  
                                 <select>
      <option>-SELECT-</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select><br /><br />
                                Date of Travel:
                                <select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>

<select>
<option>Day</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>

<select>
<option>Year</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
</select><br /><br />
                                Bus No:
                                <input type="text" class="field small-field" name='search' /><br /><br />
                                Number of Seats:
                                <input type="text" class="field small-field" name='search' /><br /><br />
                                
  <input type="submit" class="button" value="add"  name='submit'/>                          
							</form></div>
                            
                            
                           
                            
</div>
</body>
</html>

as for the inserting to the database command

reservation_insert.php

<title>Partas Bus</title>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ticket_reservation", $con);

$sql="INSERT INTO tblreservation_info (name, contact_no, email_add, origin, destination, date_of_travel, bus_no, number_of_seats )

VALUES
('$_POST[name]','$_POST[contact_no]','$_POST[email_add]','$_POST[origin]','$_POST[destination]','$_POST[date_of_travel]','$_POST[bus_no]','$_POST[number_of_seats]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

thanks for helping..........

You must have copied something wrong in reservation_insert.php , the logic thing is that your line 15 is line 14, and therefore the message speak by itself - undefined index . At least one index from the $_POST array that you are using is undefined. You could echo them before using them to figure out which one, but… to insert directly something from post to database is really – really – really bad idea. You could use PDO with prepared statements, it’s easy and you won’t have to worry about injections and those stuff.

all your <input > have the name "searche"
you have to gave them all a diffent name

Name: <input type="text" class="field small-field" name='fullname' />

the input from that field will be avaleble in reservation_insert.php
as

$_POST['fullname'];

also to prevend mysql-injections use

$name=mysql_real_escape_string($_POST['fullname']);

then use $name in your query

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.