目前我正在运行更新查询正在工作,但它允许插入空值,我不想。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