I need help to insert data into mysql. I am unable to find the problem in the code below why data is not inserted into database. When I am submitting the form this message comes : Notice: Undefined variable: asd in...
<?php
$q = mysql_query("select `cus_id`, `date`, `mobile`,
least(`t1`, `t2`, `t3`, `t4`) as min
from `table1`");
while($r = mysql_fetch_assoc($q)){
$asd = array(`cus_id` =>$r['cus_id'],
`mobile` =>$r['mobile'],
`date` =>$r['date'],
`credit` =>$r['min']);
}
$sql = array();
foreach((array)$asd as $row){
$sql[] = '("'.mysql_real_escape_string($row['cus_id']).'",
'.$row['mobile'].',
'.$row['date'].',
'.$row['min_total'].'
)';
}
$stmt = mysql_query('INSERT INTO `single` (`cus_id`, `mobile`, `date`, `credit`)
VALUES '.implode(',', $sql));
if(!$stmt){
echo "error". mysql_error();
}else{
$_SESSION['s']="Payment successfully saved";
header('location:final.php');
}
?>
Thanks for any help.