(這是所有基本的php voor學校) 我做了一個表單,您可以更新您的帳戶信息,當您點擊提交按鈕時,它會來到這個php代碼。如果一個字段沒有填寫,它不需要更新,我試過「WHERE字段不是NULL」,但它似乎不工作,它給出了一個空記錄...php sql更新只填寫在域
(變量都在荷蘭,抱歉)
$klantnummer = $_COOKIE['klantnummer'];
$naam =($_POST["naam"]);
$adres =($_POST["adres"]);
$postcode =($_POST["postcode"]);
$gemeente =($_POST["gemeente"]);
$leden =($_POST["gezinsleden"]);
$huidigemeterstand =($_POST["huidigemeterstand"]);
$vorigemeterstand =($_POST["vorigemeterstand"]);
$provincie =($_POST["provincie"]);
//set up connection and choose database
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("opdracht3", $con);
mysql_query("UPDATE waterstand SET naam = '$naam', adres = '$adres', postnummer = '$postcode', gemeente = '$gemeente', vorigemeterstand='$vorigemeterstand', huidigemeterstand='$huidigemeterstand', provincie='$provincie', aantalgezinsleden = '$gezinsleden'
WHERE klantnummer = '$klantnummer' AND naam IS NOT NULL");`
ofcourse我需要廣告的「場」的其餘部分是NOT NULL,但比如我只用「NAAM」 ..但它不工作:/
停止,它們被棄用。開始使用PDO,它會更好,更安全 –
數據庫字段中的默認值是否設置爲NULL?如果它們設置爲''或類似,那麼IS NULL檢查將不會返回true。 – Maccath
@Ben Carey:這是我們在學校學習的方式,但我會檢查出來,謝謝! – user1830235