I need a way to select the values from another table and then insert them In another table. And using the id which is posted from .
in this file i need to select data from 2 differnt table and then insert it into the table MainStrInv . Please check this code or give me a simple example how I can Select values from 2 different tables and insert into 3rd table. I need this in insert.php page which is the action of my form. Thanks in advance.
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mobilink", $con);
$a= $_POST[ItemCode];
// echo $a;
$result = mysql_query("SELECT ItemName FROM itemcodename WHERE ItemCode='$a'");
while($row = mysql_fetch_array($result))
{
$c= $row['ItemName'];
$sql="INSERT INTO MainStrInv (EntrySlipNumber, BillNo,ItemName, ItemCode, BillDate, Date, Qty, EntryType, RequesterName, SupplierName)
VALUES
('$_POST[EntrySlipNumber]','$_POST[BillNo]','$c','$_POST[ItemCode]','$_POST[BillDate]','$_POST[dt]','$_POST[Qty]','$_POST[EntryType]','$_POST[RequesterName]','$_POST[SupplierName]')";
$sql2="INSERT INTO MainStrInvmain (EntrySlipNumber, BillNo,ItemName, ItemCode, BillDate, Date, Qty, EntryType, RequesterName, SupplierName)
VALUES
('$_POST[EntrySlipNumber]','$_POST[BillNo]','$c','$_POST[ItemCode]','$_POST[BillDate]','$_POST[dt]','$_POST[Qty]','$_POST[EntryType]','$_POST[RequesterName]','$_POST[SupplierName]')";
mysql_query($sql,$con);
mysql_query($sql2,$con);
}
header('Location: MAIN_STORE_entry.php');
mysql_close($con)
?>