有id = ".$_POST['id']."
後失蹤,
這裏contact2 = ".$_POST['contact2'];
不能打破這樣
$sql = "UPDATE `members` SET id = ".$_POST['id']."
fname = ".$_POST['fname'].",
lname = ".$_POST['lname'].",
gender = ".$_POST['gender'].",
age_group = ".$_POST['age_group'].",
status = ".$_POST['status'].",
dob_day = ".$_POST['dob_day'].",
dob_month = ".$_POST['dob_month'].",
wed_anni_day = ".$_POST['wed_anni_day'].",
wed_anni_month = ".$_POST['wed_anni_month'].",
type = ".$_POST['type'].",
email = ".$_POST['email'].",
address = ".$_POST['address'].",
city = ".$_POST['city'].",
zipco = ".$_POST['zipco'].",
contact1 = ".$_POST['contact1'].",
contact2 = ".$_POST['contact2'];
行應該是
$sql = "UPDATE `members` SET id = ".$_POST['id'].",
fname = ".$_POST['fname'].",
lname = ".$_POST['lname'].",
gender = ".$_POST['gender'].",
age_group = ".$_POST['age_group'].",
status = ".$_POST['status'].",
dob_day = ".$_POST['dob_day'].",
dob_month = ".$_POST['dob_month'].",
wed_anni_day = ".$_POST['wed_anni_day'].",
wed_anni_month = ".$_POST['wed_anni_month'].",
type = ".$_POST['type'].",
email = ".$_POST['email'].",
address = ".$_POST['address'].",
city = ".$_POST['city'].",
zipco = ".$_POST['zipco'].",
contact1 = ".$_POST['contact1'].",
contact2 = ".$_POST['contact2']." ";
而且還WHERE
子句是丟失。
或者可以在查詢應該是這樣
$sql = "UPDATE `members` SET fname = ".$_POST['fname'].",
lname = ".$_POST['lname'].",
gender = ".$_POST['gender'].",
age_group = ".$_POST['age_group'].",
status = ".$_POST['status'].",
dob_day = ".$_POST['dob_day'].",
dob_month = ".$_POST['dob_month'].",
wed_anni_day = ".$_POST['wed_anni_day'].",
wed_anni_month = ".$_POST['wed_anni_month'].",
type = ".$_POST['type'].",
email = ".$_POST['email'].",
address = ".$_POST['address'].",
city = ".$_POST['city'].",
zipco = ".$_POST['zipco'].",
contact1 = ".$_POST['contact1'].",
contact2 = ".$_POST['contact2']."
WHERE
id = ".$_POST['id']." ";
做的最好的方法;
$id = mysql_real_escape_string($_POST['id']);
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$gender = mysql_real_escape_string($_POST['gender']);
$age_group = mysql_real_escape_string($_POST['age_group']);
$status = mysql_real_escape_string($_POST['status']);
$dob_day = mysql_real_escape_string($_POST['dob_day']);
$dob_month = mysql_real_escape_string($_POST['dob_month']);
$wed_anni_day = mysql_real_escape_string($_POST['wed_anni_day']);
$wed_anni_month= mysql_real_escape_string($_POST['wed_anni_month']);
$type = mysql_real_escape_string($_POST['type']);
$email = mysql_real_escape_string($_POST['email']);
$address = mysql_real_escape_string($_POST['address']);
$city = mysql_real_escape_string($_POST['city']);
$zipco = mysql_real_escape_string($_POST['zipco']);
$contact1 = mysql_real_escape_string($_POST['contact1']);
$contact2 = mysql_real_escape_string($_POST['contact2']);
$sql = "UPDATE `members` SET fname = '$fname',
lname = '$lname',
gender = '$gender',
age_group = '$age_group',
status = '$status',
dob_day = '$dob_day',
dob_month = '$dob_month',
wed_anni_day = '$wed_anni_day',
wed_anni_month = '$wed_anni_month ',
type = '$type',
email = '$email',
address = '$address',
city = '$city ',
zipco = '$zipco',
contact1 = '$contact1',
contact2 = '$contact2'
WHERE
id = '$id' ";
不要直接在數據庫中查詢從POST/GET獲得的任何數據。在使用它之前,您應該過濾/轉義。 – Tomasz