SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
;
;
;
;
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;
ALTER TABLE `form`
ADD PRIMARY KEY (`id`);
ALTER TABLE `form`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;
;
;
;
cyg.php
<?php
SESSION_START();
$_SESSION['is_submit'] = 0;
header("Content-type:text/html;charset=utf-8");
?>
<style>
body{
background:
}
.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 οnclick='history.go(-1);' href='javascript:void(0)'>返回</a>";
} else {
echo "请不用重复提交<a href='index.php'>PHP+SESSION防止表单重复提交</a>";
}
}
$link=mysqli_connect('localhost','root','','a');
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);
echo "<form>";
while ($row=mysqli_fetch_assoc($result)) {
echo $row['type']."类型:"."<input type='$row[type]' />";
}
echo "</form>";
|