I'm trying to store the 2 array values in single row. However, I got unexpected output which return extra row in the datatable.
My php:
$checkbox1=$_POST['name'];
$checkbox2=$_POST['id'];
foreach ($checkbox1 as $pop )
{
$addsql = "insert into referral () values ('$pop','{$_POST['id']}')";
$addresult = mysql_query($addsql, $link);
}
My table (ERROR):
Name ID
Alex Array
1 Array
Alice Array
2 Array
Expected Result:
Name ID
Alex 1
Alice 2
Hope this work!
$checkbox1=$_POST['name'];
$checkbox2=$_POST['id'];
foreach ($checkbox1 as $k=>$pop){
$addsql = "insert into referral () values ('$pop','$checkbox2[$k]')";
$addresult = mysql_query($addsql, $link);
}
Use mysqli
instead of mysql
to prevent hijacking...
Use instead $checkbox2
of '{$_POST['id']}'
Modify your code to
$checkbox1=$_POST['name'];
$checkbox2=$_POST['id'];
foreach ($checkbox1 as $pop )
{
$addsql = "insert into referral () values ('$pop','$checkbox2')";
$addresult = $mysqli->query($addsql, $link);
}