這裏是我的數組:列計數與第1行的值計數不匹配 - 但是我有27列和27個值? PHP MySQL錯誤
$person = array(
"fullname" => $fn,
"skin_shade" => $_POST['skin_shade'],
"acne" => $_POST['acne'],
"dry_skin" => $_POST['dry_skin'],
"oily_skin" => $_POST['oily_skin'],
"wrinkles_aging" => $_POST['wrinkles_aging'],
"sensative_skin" => $_POST['sensative_skin'],
"darkspots" => $_POST['darkspots'],
"hair_type" => $_POST['hair_type'],
"parabens" => $_POST['parabens'],
"sulfates" => $_POST['sulfates'],
"mineral_oil" => $_POST['mineral_oil'],
"silicones" => $_POST['silicones'],
"relaxed" => $_POST['relaxed'],
"colortreated" => $_POST['colortreated'],
"thinning" => $_POST['thinning'],
"growth" => $_POST['growth'],
"braidout" => $_POST['braidout'],
"roller" => $_POST['roller'],
"wng" => $_POST['wng'],
"heat" => $_POST['heat'],
"wig" => $_POST['wig'],
"braid" => $_POST['braid'],
"dreadlocks" => $_POST['dreadlocks'],
"henna" => $_POST['henna'],
"hair_color" => $_POST['hair_color'],
"hair_style" => $_POST['hair_style'],
);
這裏是我嘗試插入,並得到了錯誤:
$columns = implode(", ",array_keys($person));
$escaped_values = array_map('mysql_real_escape_string', array_values($person));
$values = implode(", ", $escaped_values);
$sql = "INSERT INTO people ($columns) VALUES ('$values')";
mysql_query($sql) or die (mysql_error());
我還用在列和值的print_r確保它們的大小相同:
print_r($columns); echo"</br></br>";
print_r($values);
這裏是輸出我得到爲:
fullname, skin_shade, acne, dry_skin, oily_skin, wrinkles_aging, sensative_skin, darkspots, hair_type, parabens, sulfates, mineral_oil, silicones, relaxed, colortreated, thinning, growth, braidout, roller, wng, heat, wig, braid, dreadlocks, henna, hair_color, hair_style
Chris Runo, 2, No, Yes, No, Yes, Yes, No, Straight, No, No, No, No, No, No, No, Yes, No, No, No, No, No, No, No, No, dark_brown, classic
我也檢查了我的MySQL表,並有27列。