<?php
if ( !isset($_POST['sendBtn']) ) {
echo "please click the 'send' botton !";
exit();
} // end if ( !isset($_POST['sendBtn']) )
$a = array('city', 'product', 'sale', 'shop');
if ( !empty($_POST['arg']) ) {
$ar = $_POST['arg'];
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('dbName');
} else {
echo "there is not any rows to insert in table";
exit();
} // end else
$flag = false;
$row_insert = 0;
for ($i=0; $i<count($ar); $i++) {
foreach ( $a as $key ) {
if ( empty($ar[$i][$key]) )
$flag = true;
} // end foreach ( $a as $key )
if ( !$flag ) {
$row_insert ++;
$sale = intval($ar[$i]['sale']);
$shop = intval($ar[$i]['shop']);
$qry = "INSERT INTO `dbName`.`tbName` (`city`, `product`, `sale`, `shop`) VALUES( '$ar[$i][city]', '$ar[$i][product]', '$sale', '$shop' ); ";
$result[$i] = mysql_query ( $qry, $con );
if ( !$result[$i] )
echo "<br/>could not insert into table where row = \$ar[$i] : " . mysql_error();
else
echo "<br/>successfuly, insett into table where row = \$ar[$i] ";
} // end if ( !$flag )
$flag = false;
} // end for ($i=0; $i<count($ar); $i++)
echo "<br/><br/>now, <b>$row_insert</b> row(s) inserted in table !";
?>