如何将循环值插入数据库,将所有值存储到数组中,请看一下并建议我
$data['name'] = mysql_real_escape_string($_POST['name']);
$data['email'] = $_POST['email'];
$data['password'] = $_POST['password'];
$data['gender'] = $_POST['gender'];
$data['dob'] = $_POST['dob'];
$data['address'] = $_POST['address'];
$data['country'] = $_POST['country'];
$data['hobbie'] = $_POST['hobbie'];
$checkElement = "";
foreach($data['hobbie'] as $check=>$chkValue){
$checkElement = $chkValue.","."<br>";
echo $data['hobbie']= $checkElement;
// here i am getting all value
}
//outside of loop i am getting only last value
答案 0 :(得分:1)
$data['name'] = mysql_real_escape_string($_POST['name']);
$data['email'] = $_POST['email'];
$data['password'] = $_POST['password'];
$data['gender'] = $_POST['gender'];
$data['dob'] = $_POST['dob'];
$data['address'] = $_POST['address'];
$data['country'] = $_POST['country'];
$Hobbie = $_POST['hobbie'];
$TotalCheckedHobbie=sizeof($Hobbie);
$Hobbies = "";
for($i=0;$i<$TotalCheckedHobbie;$i++)
{
$Hobbie=$Hobbie[$i];
$Hobbies=$Hobbie.",";
}
echo $Hobbies;