建立form表单
<form action="addchuli.php" method="post"> <div>水果代号:<input type="text" name="ids" /></div> <div>水果名称:<input type="text" name="name" /></div> <div>水果价格:<input type="text" name="price" /></div> <div>水果产地:<input type="text" name="source" /></div> <div>水果库存:<input type="text" name="numbers" /></div> <div><input type="submit" value="添加" /></div> </form>
连接数据库的处理
<?php
$ids = $_POST["ids"]; $name = $_POST["name"]; $source = $_POST["source"]; $price = $_POST["price"]; $numbers = $_POST["numbers"]; $db = new MySQLi("localhost","root","123","mydb"); $sql = "insert into fruit values('{$ids}','{$name}', {$price},'{$source}',{$numbers},'')"; if($db->query($sql)){ echo "添加成功!"; }else{ echo "添加失败!"; }