my code is not working it's showing error in condition.
<?
foreach($_POST['check'] as $value )
foreach($_POST['emp'] as $value2 )
{
mysql_query("insert into tb_recived_jobs set job_id='$value'emp_id='$value2'");
}
?>
my code is not working it's showing error in condition.
<?
foreach($_POST['check'] as $value )
foreach($_POST['emp'] as $value2 )
{
mysql_query("insert into tb_recived_jobs set job_id='$value'emp_id='$value2'");
}
?>
You should use For loop to do this
$count = count($_POST['check']);
for($i=0;$i<=$count;$i++) {
$value= $_POST['check'][$i];
$value2= $_POST['emp'][$i];
mysql_query("insert into tb_recived_jobs(job_id,emp_id) values('$value','$value2')");
}
correct your SQL Query like this :
"insert into tb_recived_jobs set job_id='$value' emp_id='$value2'"
you are missing one space between first value and second column, make an INSERT SQL query like this one helps much more:
"INSERT INTO `tb_recived_jobs` (`job_id`, `emp_id`) VALUES ('$value', '$value2');"
UPDATE: I just realized what is wrong exactly, cause here you have two arrays and you want to insert their values by a query, in this case both arrays should have same length to everything goes well
$checks = $_POST['check'];
$emps = $_POST['emp'];
$length = count($checks);
if ($length === count($emps)) {
for ($i = 0; $i < $length; $i++) {
$sql = "INSERT INTO `tb_received_jobs` (`job_id`, `emp_id`) VALUES ('{$checks[$i]}', '{$emps[$i]}');";
// send the query
}
}
this should work properly.
You can merge two array $_POST['check'] and $_POST['emp'] in one array after than you can use foreach for this.
try this as i understand if you want to insert each $_POST['emp']
for every $_POST['check']
<?
foreach($_POST['check'] as $value )
{
foreach($_POST['emp'] as $value2 )
{
mysql_query("INSERT INTO `tb_recived_jobs`(job_id, emp_id) VALUES('$value', '$value2')") or die(mysql_error());
}
}
?>