-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 2022-03-31 14:41:20
-- 服务器版本: 10.1.13-MariaDB
-- PHP Version: 5.6.21
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `a`
--
-- --------------------------------------------------------
--
-- 表的结构 `form`
--
CREATE TABLE `form` (
`id` int(11) NOT NULL,
`type` varchar(255) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '类型'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `form`
--
ALTER TABLE `form`
ADD PRIMARY KEY (`id`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `form`
--
ALTER TABLE `form`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
cyg.php
<?php
SESSION_START();
$_SESSION['is_submit'] = 0;
header("Content-type:text/html;charset=utf-8");
?>
<style>
body{
background:#ccc;
}
.blue
{
background:rgba(255,123,169);
width: 260px;
height:auto;
}
</style>
<form action="cyg1.php" method="POST">
您喜欢的水果?<br /><br />
<label><input name="text" type="checkbox" value="text" />文本类型</label> <br>
<label><input name="color" type="checkbox" value="color" />颜色类型</label> <br>
<label><input name="date" type="checkbox" value="date" />日期类型</label> <br>
<label><input name="password" type="checkbox" value="password" />密码类型</label> <br>
<input name="button" type="checkbox" value="button"/>按钮类型</label> <br>
<input name="email" type="checkbox" value="email" />邮箱类型</label> <br>
<input name="number" type="checkbox" value="number" />数字类型</label>
<input type="submit" value="提交">
</form>
cyg1.php
<?php
SESSION_START(); //防止表单重复提交
if (isset($_POST['submit'])) {
if ($_SESSION['is_submit'] == '0') {
$_SESSION['is_submit'] = '1';
echo "代码块,要做的事,代码...<a onclick='history.go(-1);' href='javascript:void(0)'>返回</a>";
} else {
echo "请不用重复提交<a href='index.php'>PHP+SESSION防止表单重复提交</a>";
}
}
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
$arr=[$_POST['text'],$_POST['color'],$_POST['date'],$_POST['password'],$_POST['button'],$_POST['email'],$_POST['number']];
foreach ($arr as $key => $value) {
if(empty($value))
{
unset( $arr[$key] );
}
}
foreach ($arr as $key => $value)
{
$sql = "INSERT INTO form(type)
VALUES ('{$value}')";
mysqli_query($link,$sql);
}
$sql="select type from form";
$result=mysqli_query($link,$sql);//运行sql
echo "<form>";
while ($row=mysqli_fetch_assoc($result)) {
echo $row['type']."类型:"."<input type='$row[type]' />";
}
echo "</form>";