Home  >  Article  >  Backend Development  >  Detailed explanation of how to implement the product adding function in PHP and write it to the database

Detailed explanation of how to implement the product adding function in PHP and write it to the database

PHPz
PHPzforward
2023-03-29 10:09:15842browse

This article brings you relevant knowledge about PHP. It mainly introduces how to implement the product adding function through PHP and write it into the database. Friends who are interested can take a look at it together. I hope it will be helpful to everyone. .

Detailed explanation of how to implement the product adding function in PHP and write it to the database

Database TableDetailed explanation of how to implement the product adding function in PHP and write it to the database Code for writing data

<?php include("conn/conn.php");

 header ( "Content-type: text/html; charset=gb2312" );
?>


<meta>
<title>添加商品</title>
<link>
<style>
<!--
.style1 {color: #FFFFFF}
-->
</style>

<?php  include("conn/conn.php");?>

                     
添加商品
<script> function chkinput(form) { if(form.mingcheng.value=="") { alert("请输入商品名称!"); form.mingcheng.select(); return(false); } if(form.huiyuanjia.value=="") { alert("请输入商品会员价!"); form.huiyuanjia.select(); return(false); } if(form.shichangjia.value=="") { alert("请输入商品市场价!"); form.shichangjia.select(); return(false); } if(form.dengji.value=="") { alert("请输入商品等级!"); form.dengji.select(); return(false); } if(form.pinpai.value=="") { alert("请输入商品品牌!"); form.pinpai.select(); return(false); } if(form.xinghao.value=="") { alert("请输入商品型号!"); form.xinghao.select(); return(false); } if(form.shuliang.value=="") { alert("请输入商品数量!"); form.shuliang.select(); return(false); } if(form.jianjie.value=="") { alert("请输入商品简介!"); form.jianjie.select(); return(false); } return(true); } </script>                                                                                                                                                                                                                                                                                                                                                                                                 
商品名称:
上市时间:
           年                      月                      日
价格:
市场价:           元  会员价:                      元
商品类型:
                                              
商品等级:
                   
商品品牌:
商品型号:
是否推荐:
                
      
商品数量:
商品图片:
        
商品简介:
        
          

Save the processing file for writing data

<?php header ( "Content-type: text/html; charset=gb2312" ); //设置文件编码格式
include("conn/conn.php");
if(is_numeric($_POST[&#39;shichangjia&#39;])==false || is_numeric($_POST[&#39;huiyuanjia&#39;])==false)
 {
   echo "<script>alert('价格只能为数字!');history.back();";
   exit;
 }
if(is_numeric($_POST['shuliang'])==false)
 {
   echo "<script>alert(&#39;数量只能为数字!&#39;);history.back();</script>";
   exit;
 }
$mingcheng=$_POST['mingcheng'];
$nian=$_POST['nian'];
$yue=$_POST['yue'];
$ri=$_POST['ri'];
$shichangjia=$_POST['shichangjia'];
$huiyuanjia=$_POST['huiyuanjia'];
$typeid=$_POST['typeid'];
$dengji=$_POST['dengji'];
$xinghao=$_POST['xinghao'];
$pinpai=$_POST['pinpai'];
$tuijian=$_POST['tuijian'];
$shuliang=$_POST['shuliang'];
$upfile=$_POST['upfile'];

if(ceil(($huiyuanjia/$shichangjia)*100)alert('商品".$mingcheng."添加成功!');window.location.href='addgoods.php';";
?>
recommends learning: "PHP Video Tutorial"

The above is the detailed content of Detailed explanation of how to implement the product adding function in PHP and write it to the database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete