Hello.
I am having a bit problem with the insert query, Every thing is fine but don't know why its not inserting the queries.
Have a look onm code;
function insert()
{
var table=document.getElementById("myTable1");
var table=document.getElementById("myTable");
<?php
$con=mysqli_connect("localhost","root","","bsc_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Inserting the basic information of the PATIENT;
$sql="INSERT INTO pat_t (pid, pname, fhname, gender, age, adate, ddate, tby, issue, gtotal, visit)
VALUES
('$_POST[pid]','$_POST[pname]','$_POST[fhname]','$_POST[gender]','$_POST[age]','$_POST[adate]','$_POST[ddate]','$_POST[tby]','$_POST[issue]','$_POST[gtotal]','$_POST[visit]')";
if (!mysqli_query($con,$sql))
{
//die('Error: ' . mysqli_error());
}
//qty 1
if ('$_POST[qty]' != "")
{
$sql1="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med]','$_POST[qty]','$_POST[rate]','$_POST[total]')";
if (!mysqli_query($con,$sql1))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 2
if ('$_POST[qty2]' != "")
{
$sql2="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med2]','$_POST[qty2]','$_POST[rate2]','$_POST[total2]')";
if (!mysqli_query($con,$sql2))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 3
if ('$_POST[qty3]' != "")
{
$sql3="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med3]','$_POST[qty3]','$_POST[rate3]','$_POST[total3]')";
if (!mysqli_query($con,$sql3))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 4
if ('$_POST[qty4]' != "")
{
$sql4="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med4]','$_POST[qty4]','$_POST[rate4]','$_POST[total4]')";
if (!mysqli_query($con,$sql4))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 5
if ('$_POST[qty5]' != "")
{
$sql5="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med5]','$_POST[qty5]','$_POST[rate5]','$_POST[total5]')";
if (!mysqli_query($con,$sql5))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 6
if ('$_POST[qty6]' != "")
{
$sql6="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med6]','$_POST[qty6]','$_POST[rate6]','$_POST[total6]')";
if (!mysqli_query($con,$sql6))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 7
if ('$_POST[qty7]' != "")
{
$sql7="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med7]','$_POST[qty7]','$_POST[rate7]','$_POST[total7]')";
if (!mysqli_query($con,$sql7))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 8
if ('$_POST[qty8]' != "")
{
$sql8="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med8]','$_POST[qty8]','$_POST[rate8]','$_POST[total8]')";
if (!mysqli_query($con,$sql8))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 9
if ('$_POST[qty9]' != "")
{
$sql9="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med9]','$_POST[qty9]','$_POST[rate9]','$_POST[total9]')";
if (!mysqli_query($con,$sql9))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
//qty 10
if ('$_POST[qty10]' != "")
{
$sql10="INSERT INTO pmed_t (visit, pid, medname, qty, rate, total)
VALUES
('$_POST[visit]','$_POST[pid]','$_POST[med10]','$_POST[qty10]','$_POST[rate10]','$_POST[total10]')";
if (!mysqli_query($con,$sql10))
{
//die('Error: ' . mysqli_error());
}
}
echo "";
mysqli_close($con);
?>
}
When I check the database on localhost. It is inserting only one row in the pat_t table and pmed_t table. every thing(field in the DB table) is showing "0".
Please help me to find out where i am making a mistake...
Thanks n Regards.