将字段留空时出现PHP表单错误

将字段留空时出现PHP表单错误,php,mysql,forms,Php,Mysql,Forms,我有一个PHP表单,当我将一个字段留空时,它会带来一个错误 很抱歉,在重复键更新clientID='45',clientName='Frank'上将此客户端sql=insert添加到db1.cleints(clientID,clientName)值(45,Frank)时出错。您的sql语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“clientName”附近使用的正确语法 更新:我已经包括了代码是什么。请忽略这样一个事实,我的上述只是一个修改过的例子 $sql = "inser

我有一个PHP表单,当我将一个字段留空时,它会带来一个错误

很抱歉,在重复键更新clientID='45',clientName='Frank'上将此客户端sql=insert添加到db1.cleints(clientID,clientName)值(45,Frank)时出错。您的sql语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“clientName”附近使用的正确语法

更新:我已经包括了代码是什么。请忽略这样一个事实,我的上述只是一个修改过的例子

 $sql = "insert into $DB.theater (dsc_id, dsc_lname, dsc_fname, distributor_id, distributor_name, distributor_theater_id, manager_id, manager_name, is_new_theater, name, phone_area, phone_exch, phone_local, phone_ext, street, city, state_prov, country, postal, web_site_url, manager_gender, theater_manager_name, email, location_desc, square_footage, year_founded, colors_techs, stylists, assistants, active_chairs, booth_renters, services, purchase_volume, products, other_lines, other_lines_txt, percent_women, demog_lt_20, demog_lt_35, demog_lt_55, demog_ge_55, avg_sale, avg_cut, avg_color, avg_hilite, rating, can_display, retail_sf, grade, dsc_notes) values ($dsc_id, '$dsc_lname', '$dsc_fname', $distributor_id, '$distributor_name', '$distributor_theater_id', $manager_id, '$manager_name', '$is_new_theater', '$name', '$phone_area', '$phone_exch', '$phone_local', '$phone_ext', '$street', '$city', '$state_prov','$country', '$postal', '$web_site_url', '$manager_gender', '$theater_manager_name', '$email', '$location_desc', '$square_footage', '$year_founded', '$colors_techs', '$stylists', '$assistants', '$active_chairs', '$booth_renters', '$services', '$purchase_volume', '$products', '$other_lines','$other_lines_txt', '$percent_women', '$demog_lt_20', '$demog_lt_35', '$demog_lt_55', '$demog_ge_55', '$avg_sale', '$avg_cut', '$avg_color', '$avg_hilite', '$rating', '$can_display', '$retail_sf', '$grade', '$dsc_notes') on duplicate key update dsc_id=$dsc_id, dsc_lname='$dsc_lname', dsc_fname='$dsc_fname', distributor_id=$distributor_id, distributor_name='$distributor_name', distributor_theater_id='$distributor_theater_id', manager_id=$manager_id, manager_name='$manager_name', is_new_theater='$is_new_theater', name='$name', phone_area='$phone_area', phone_exch='$phone_exch', phone_local='$phone_local', phone_ext='$phone_ext', street='$street', city='$city', state_prov='$state_prov', country='$country', postal='$postal', web_site_url='$web_site_url', manager_gender='$manager_gender', theater_manager_name='$theater_manager_name', email='$email', location_desc='$location_desc', square_footage='$square_footage', year_founded='$year_founded', colors_techs='$colors_techs', stylists='$stylists', assistants='$assistants', active_chairs='$active_chairs', booth_renters='$booth_renters', services='$services', purchase_volume='$purchase_volume', products='$products', other_lines='$other_lines', other_lines_txt='$other_lines_txt', percent_women='$percent_women', demog_lt_20='$demog_lt_20', demog_lt_35='$demog_lt_35', demog_lt_55='$demog_lt_55', demog_ge_55='$demog_ge_55', avg_sale='$avg_sale', avg_cut='$avg_cut', avg_color='$avg_color', avg_hilite='$avg_hilite', rating='$rating', can_display='$can_display', retail_sf='$retail_sf', grade='$grade', dsc_notes='$dsc_notes'";
第一个
Frank
没有被引用

另外,值得注意的是,重复键更新的
的全部目的是能够在记录不存在时插入记录,或者在记录已经存在时更新记录。您正在尝试使用已具有的相同值进行更新。也许你想要

更新问题的答案:

看来我们得猜了。我有根据地猜测,您并不是在逃避输入数据。相反,您将盲目地将其注入到SQL代码中。当一个数字字段留空时,不能用正确的NULL替换它;它只是铸造到(空白)字符串:

。。。生成:

VALUES(1, , 3)
如果您在该字段中键入字母,或者键入
O'Hara
,则可能也会失败

第一个
Frank
没有被引用

另外,值得注意的是,重复键更新的
的全部目的是能够在记录不存在时插入记录,或者在记录已经存在时更新记录。您正在尝试使用已具有的相同值进行更新。也许你想要

更新问题的答案:

看来我们得猜了。我有根据地猜测,您并不是在逃避输入数据。相反,您将盲目地将其注入到SQL代码中。当一个数字字段留空时,不能用正确的NULL替换它;它只是铸造到(空白)字符串:

。。。生成:

VALUES(1, , 3)

如果您在这样的字段中键入字母,或者键入
O'Hara

@Mike,它可能也会失败,看起来您的INSERT查询出现了MySQL错误。你能包含运行这样一个查询的代码吗?我已经用code@Mike:PHP代码不会触发MySQL错误。你的问题在于你的SQL代码。我应该提到这是在Windows Server上运行的2008@Mike您还需要更新错误消息,因为您发布的代码中没有
clientName
clientID
。@Mike,看起来您的插入查询出现了MySQL错误。你能包含运行这样一个查询的代码吗?我已经用code@Mike:PHP代码不会触发MySQL错误。你的问题在于你的SQL代码。我应该提到这是在Windows Server上运行的2008@Mike您还需要更新错误消息,因为您发布的代码中没有
clientName
clientID
,因此它不再有意义。
VALUES(1, , 3)