目前我正在運行更新查詢正在工作,但它允許插入空值,我不想。SQL查詢錯誤 - 邏輯或語法
mysql_query('UPDATE community_table SET
age = "'.$age.'",
gender = "'.$gender.'",
pregnant = "'.$pregnant.'",
diet = "'.$diet.'",
smoker = "'.$smoker.'",
alcohol = "'.$alcohol.'",
exercise = "'.$exercise.'",
bmi = "'.$bmi.'",
sleeping = "'.$sleeping.'",
stress = "'.$stress.'",
education = "'.$education.'"
WHERE username = "' . $_SESSION['user'] . '" ');
我試過這個查詢似乎可以防止輸入空值,但是它也可以防止在變量不爲空時輸入值。
age = "'.$age.'",
gender = "'.$gender.'",
pregnant = "'.$pregnant.'",
diet = "'.$diet.'",
smoker = "'.$smoker.'",
alcohol = "'.$alcohol.'",
exercise = "'.$exercise.'",
bmi = "'.$bmi.'",
sleeping = "'.$sleeping.'",
stress = "'.$stress.'",
education = "'.$education.'"
WHERE age IS NOT NULL,
gender IS NOT NULL,
pregnant IS NOT NULL,
diet IS NOT NULL,
smoker IS NOT NULL,
alcohol IS NOT NULL,
exercise IS NOT NULL,
bmi IS NOT NULL,
sleeping IS NOT NULL,
stress IS NOT NULL,
education IS NOT NULL and where
username = "' . $_SESSION['user'] . '" ');
上面的查詢是否有問題,或者我的輸入中是否有空值?
謝謝。
? – Bajrang
我不爲其分配新值的任何列。基本上任何以前的值都被轉換爲空值,除非我重新分配一個值給他們。他們不保留以前的價值。 – user1334130