mysql - PHP validation if not exists price -
i have 2 inputs price1 , price2. , if have 1 price add price1 , price2 empty. want add database , in database in price 2 doesnt have
php:
if(isset($_post["submitmenu"])){ $menu_item_category = $_post["menu_item_category"]; $menu_item_name = $_post["menu_item_name"]; $menu_item_details = $_post["menu_item_details"]; $menu_price1 = $_post["menu_price1"]; $menu_price2 = $_post["menu_price2"]; $query_orders = "insert menus (menu_item_category,menu_item_name,menu_item_details, menu_price1, menu_price2) values ('$menu_item_category','$menu_item_name','$menu_item_details', '$menu_price1', '$menu_price2');"; mysqli_query($con, $query_orders); } sql:
create table if not exists `menus` ( `menu_item_id` int(10) not null auto_increment, `menu_item_category` varchar(100) not null, `menu_item_name` varchar(100) not null, `menu_item_details` varchar(300) default null, `menu_price1` double not null, `menu_price2` double not null, `menu_date` timestamp null default null, primary key (`menu_item_id`) ) engine=innodb default charset=latin1 auto_increment=244 ; its working when add 2 prices.
example:
price1 = 20
price2 = 30
then working , sending database. if dont insert price price2 not sending database.
example:
price1 = 20
price2
the issue table set menu_price2 not null. either alter table allow null or try
$menu_price2 = empty($_post["menu_price2"]) ? $_post["menu_price2"] : 0;
Comments
Post a Comment