简体   繁体   English

PHP和MySQL问题

[英]PHP & MySQL question

I was wondering how can I stop an empty value from being entered into my MySQL database in the example below which will enter nothing in to the database, so that my MySQL Default NULL value is displayed in the database? 我想知道如何在下面的示例中阻止将空值输入我的MySQL数据库,而该空值不会向数据库中输入任何内容,以便在数据库中显示我的MySQL Default NULL值?

if(empty($_POST['username'])){
    $u = NULL;
}
$u='NULL'

then your SQL query could be 那么你的SQL查询可能是

UPDATE myTable(user) INSERT user=$u WHERE id='12345';

Don't forget to sanitize the data you received from the user! 不要忘记清理从用户那里收到的数据!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM