I want to fetch multiple row data from one table and on users selection, store only the chosen row into another table.
The problem with this code is that data from table 'FLIGHTS' is fetching accurately from database but when I am trying to store it into another table 'bookFlight' it is storing only NULL values for all columns. Want help!
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("dbtest",$dbhandle)
or die("Could not select dbtest");
session_start();
////// STORING DATA INTO TABLE 'bookFlight' ////////
if(isset($_POST['Submit']))
{
$company_name = mysql_real_escape_string($_POST['company_name']);
$flight_category= mysql_real_escape_string($_POST['flight_category']);
$rates = mysql_real_escape_string($_POST['rates']);
$qry = "INSERT INTO bookFlight"."(company_name,flight_category,rates)".
"VALUES('$company_name','$flight_category','$rates')";
$retval = mysql_query( $qry, $dbhandle );
if(! $retval ) {
die('<br><br> Could not enter data: ' . mysql_error());
}
else { echo "Entered data successfully\n"; }
}
////// FETCHING DATA FROM TABLE 'flights' ////////
$sql = "SELECT * FROM flights where type_id =
(SELECT type_id FROM tour WHERE city =
'{$_SESSION['destination_Address']}')";
$myData = mysql_query($sql,$dbhandle);
$num = mysql_num_rows($myData);
echo "<table border=1>
<tr>
<th> COMPANY NAME : </th>
<th> FLIGHT CATEGORY : </th>
<th> RATES : </th>
</tr>";
for ($i=0; $i <$num; $i++)
{
$record = mysql_fetch_array($myData,MYSQL_ASSOC);
echo "<form method=post>";
echo "<tr>";
echo "<td>" . $company_name[]= $record['company_name'] ."</td>";
echo "<td>" . $flight_category[]= $record['flight_category']."</td>";
echo "<td>" . $rates[]= $record['rates'] ." </td>";
echo "<td>" . "<input type='submit' name='Submit' value='SELECT'></td>";
echo "</tr>";
}
echo"</table>";
echo "</form>";
?>