这里接着我项目分享sell篇
sell.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" type="text/css" href="../images/bird.png" >
<link rel="stylesheet" type="text/css" href="sell.css">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$.ajaxSetup( {
data: {
csrfmiddlewaretoken: '{csrf_token}'
}
} )
</script>
<title>我要出售</title>
</head>
<body>
<header>
<h1 align="center">请填写下面信息!</h1>
</header>
<div id="main">
<form action="sell_accept.php" name="form" id=" form"method="post" enctype="multipart/form-data">
<br/> 请选择你要出售的商品图片
<input id="file" name="file[]" onchange="changepic(this)" type="file" multiple accept="image/*">
<div style="border:dashed;border-color: #F1B5FA">
<h1>预览框只显示前9张</h1>
<img src="" alt="" width="200px" height="200px"/>
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
<img src="" alt="" width="200px" height="200px">
</div>
<br/>商品属性:
<label>
<input type="checkbox" name="choice[]" id='choice' value="1">生活用品</label>
<label>
<input type="checkbox" name="choice[]"
id='choice' value="2">学习用品</label>
<label><input type="checkbox" name="choice[]" id='choice'value="3">闲置交易</label>
<label><input type="checkbox" name="choice[]" id='choice'value="4">其他
</label><span id="choice">*</span>
<br/>商品名:<input type=text id="shopname" name="shopname"placeholder="输入您的商品名"><span id="shopname">*</span>
<br/>
<p style="display: inline">商品描述(不多于30字):<textarea id="selltext" name="word" placeholder="输入您的商品描述"></textarea>
<span id="text">*</span>
</p>
<br/> 填写您的姓名
<input type="text" id="name" name="name" placeholder="输入您的名字"><span id="name">*</span>
<br/>您的电话<input type="text" id="phone" name="phone" placeholder="输入您的电话"><span id="phone">*</span>
<br/>您的微信号<input type="text" id="wechat" name="wechat" placeholder="输入您的微信">
<span id="wechat"></span>
<br/>您的邮箱<input type="text" id="e-mail" name="e-mail" placeholder="输入您的邮箱">
<span id="e-mail"></span>
<br/>您的身份是:
<label><input type="radio" name="id" id="id" value="0">学生</label>
<label><input type="radio" name="id" id="id" value="1">老师</label>
<label><input type="radio" name="id" id="id"value="2">职工</label>
<label><input type="radio" name="id" id="id"value="3">校外人士</label>
<span id="id">*</span>
<br/>
<input type="submit" id="submit" onClick="check();return false;">
<input type="reset" id="reset" value="重置"><button style="position: relative; margin-left: 4px"><a href="../index.php" style="text-decoration: none;color: black">返回页面</a></button>
</form>
</div>
<footer style="text-align: center"><hr style="width: -webkit-fill-available;"> @year:2019.6-10.-@author:bo</footer>
</body>
<script type="text/javascript">
$(document).ready(function(){
if($( "#phone" ).val()){
$("span#choice").html("√");
$("span#shopname").html("√");
$("span#text").html("√");
$("span#name").html("√");
$("span#phone").html("√");
$("span#id").html("√");
}
});
function changepic( obj ) {
//console.log(obj.files[0]);//这里可以获取上传文件的name
for ( var a = 0; a < obj.files.length; a++ ) {
var newsrc = getObjectURL( obj.files[ a ] );
document.getElementsByTagName( "img" )[ a ].src = newsrc;
}
}
//建立一個可存取到該file的url
function getObjectURL( file ) {
var url = null;
// 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已
if ( window.createObjectURL != undefined ) { // basic
url = window.createObjectURL( file );
} else if ( window.URL != undefined ) { // mozilla(firefox)
url = window.URL.createObjectURL( file );
} else if ( window.webkitURL != undefined ) { // webkit or chrome
url = window.webkitURL.createObjectURL( file );
}
return url;
}
$("#reset").click(function(){
$("span#choice").html("*");
$("span#shopname").html("*");
$("span#text").html("*");
$("span#name").html("*");
$("span#phone").html("*");
$("span#id").html("*");
$("span#wechat").html("");
$("span#e-mail").html("");
});
$( "#phone" ).on('input propertychange',function () {let a = $( "#phone" ).val();
let reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
if ( a == "" ) {
$( "span#phone" ).html( "*" );
} else {
if ( reg.test( a ) ) {
$( "span#phone" ).html( "√" );
} else {
$( "span#phone" ).html( "输入错误,请输入正确手机号!" );
}
}
}
);
$( "#name" ).on('input propertychange',function () {
let a = $( "#name" ).val();
if ( a == "" ) {
$( "span#name" ).html( "*" );
} else {
$( "span#name" ).html( "√" );
}
} );
$( "textarea#selltext" ).on('input propertychange',function () {
let a = $( "#selltext" ).val();
if ( a.length == 0 ) {
$( "span#text" ).html( "*" );
} else {
if ( a.length > 0 && a.length <= 30 ) {
$( "span#text" ).html( "√" );
} else {
$( "span#text" ).html( "超出字数!" );
}
}
} );
$( "#e-mail" ).on('input propertychange',function () {
let a = $( "#e-mail" ).val();
if(a){
if ( a.length != 0 ) {
let reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if ( !reg.test( a ) ) {
$( "span#e-mail" ).html( "输入格式错误" );
} else
$( "span#e-mail" ).html( "√" );
}}
else{
$( "span#e-mail" ).html( "" );
}
} );
$( "#wechat" ).on('input propertychange',function () {
let a = $( "#wechat" ).val();
if ( a.length != 0 ) {
$( "span#wechat" ).html( "√" );
}else{
$( "span#wechat" ).html( "" );
}
} );
$( "#shopname" ).on('input propertychange',function () {
let a = $( "#shopname" ).val();
if ( a.length != 0 ) {
$( "span#shopname" ).html( "√" );
}else{
$( "span#shopname" ).html( "*" );
}
} );
$("input#id").on('change propertychange',function(){
let a=$('input:radio:checked').val();
if(a){
$("span#id").html("√");
}
});
$("input#choice").on('change propertychange',function(){
let a=$('input:checkbox:checked').val();
if(a){
$("span#choice").html("√");
}
else{
$("span#choice").html("*");
}
})
function check() {
let a=$("span#choice").html()+$("span#shopname").html()+$("span#text").html()+$("span#name").html()+$("span#phone").html()+$("span#id").html();
let reg=/√{6}/;
let b=$("span#choice").html()+$("span#shopname").html()+$("span#text").html()+$("span#name").html()+$("span#phone").html()+$("span#id").html()+$("span#wechat").html()+$("span#e-mail").html();
let reg1=/[^√*]+/;
if(!reg1.test(b)){
if(reg.test(a))
{
if (confirm( "请确认信息!\n是否确认提交")) {
send();
}
else{
return false;
}
}
else{
alert("未输入必要内容!");
}
}
else{
alert("输入错误!");
}
}
</script>
</html>
sell.css
/* CSS Document */
@keyframes change {
0% {
color:red;
}
25% {
color:blue;
}
50% {
color:yellow
}
75% {
color:goldenrod
}
100% {
rgba(0,0,100,0.3)
}
}
body{
background: #F5BDBE;
font-family: 'Comic Sans MS', cursive, sans-serif;
}
header{
animation: change 5s infinite;
}
#main{
vertical-align: middle;
border-color: cadetblue;
border: solid;
border-style: outset;
text-align: center;
background: #FAEE86;
}
#selltext{
word-break: normal;
width: 300px;
height: 100px;
overflow: hidden;
}
textarea{
padding: 10px;
margin: 5px;
}
input{
padding: 3px;
}
span{
color: red;
font-size: 1.2em;
}
sell_accept.php
<?php session_start()?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;" />
<?php header('Access-Control-Allow-Origin:*')?>
<title>acceptphp</title>
<script type="text/javascript">
$(document).ready(function(){
<?php
@$s=$_SESSION['name'];
if(!isset($_SESSION['name'])){
echo 'alert("请先登录!");
window.stop();';
}
?>
});
var a=5;
setInterval(count,1000);
function count(){
$("h1").text("页面五秒后跳转...."+a--+"s");
}
</script>
</head>
<body >
<div align="center">
<h1></h1>
<table border="soild">
<tr>
<th colspan="2">提交信息确定</th>
</tr>
<?php
@$shopname=$_POST['shopname'];
echo "<tr><td>商品名</td><td>";
if ( !$shopname) {
echo "null";
} else{
echo $shopname;
}
echo "</td></tr>";
@$carray=$_POST['choice'];
$c = null;
echo "<tr><td>商品属性</td><td>";
if ( !$carray) {
echo "null";
} else {
if (@$carray[0] ) {
echo "生活用品.";
$c .= "生活用品.";
}
if (@$carray[1] ) {
echo "学习用品.";
$c .= "学习用品.";
}
if (@$carray[2] ) {
echo "闲置交易.";
$c .= "闲置交易.";
}
if ( @$carray[3] ) {
echo "其他.";
$c .= "其他.";
}
}
echo "</td></tr>";
@$n = $_POST[ "name" ];
echo "<tr><td>姓名</td><td>";
if ( $n == null ) {
echo "null";
} else {
echo $n;
}
echo "</td></tr>";
@$w = $_POST[ "word" ];
echo "<tr><td>详细描述</td><td>";
if ( $w == NULL ) {
echo "null";
} else {
echo $w;
}
echo "</td></tr>";
@$p = $_POST[ "phone" ];
echo "<tr><td>手机号</td><td>";
if ( $p == NULL ) {
echo "null";
} else {
echo $p;
}
echo "</td></tr>";
@$e = $_POST[ "e-mail" ];
echo "<tr><td>邮箱地址</td><td>";
if ( $e == NULL ) {
echo "null";
} else {
echo $e;
}
echo "</td></tr>";
@$i
= $_POST[ "id" ];
echo "<tr><td>身份</td><td>";
if ( $i == NULL ) {
echo "null";
} else {
if ( $_POST[ "id" ] == 0 ) {
echo "学生";
}
if ( $_POST[ "id" ] == 1 ) {
echo "老师";
}
if ( $_POST[ "id" ] == 2 ) {
echo "职工";
}
if ( $_POST[ "id" ] == 3 ) {
echo "校外人士";
}
}
echo "</td></tr>";
@$wc = $_POST[ "wechat" ];
echo "<tr><td>微信</td><td>";
if ( $wc == NULL ) {
echo "null";
} else {
echo $wc;
}
echo "</td></tr>";
echo "<tr><td>上传的文件</td><td>";
$a=print_r($_FILES['file']['name'][0],true);
if ( $a!=null){
$count = count( $_FILES[ "file" ][ "name" ] );
@mkdir( "../pic/".$_SESSION["name"].'/'.$shopname);
echo "上传共".$count.'个文件<br/>';
for ( $f = 0; $f < $count; $f++ ) {
if ( file_exists( "../pic/" .$_SESSION["name"].'/'.$shopname.'/'.$_FILES[ "file" ][ "name" ][ $f ] ) ) {
echo $_FILES[ "file" ][ "name" ][ $f ] . " already exists. ";
} else {
echo
move_uploaded_file( $_FILES[ "file" ][ "tmp_name" ][ $f ],
"../pic/".$_SESSION["name"] .'/'.$shopname.'/'.$_FILES[ "file" ][ "name" ][ $f ] );
echo "Stored in: " . "../pic/" .$_SESSION["name"].'/'.$shopname.'/'. $_FILES[ "file" ][ "name" ][ $f ] . "<br/>";
}
echo "成功!<br/>";
// echo "fail:" . $_FILES[ 'file' ][ 'error' ][ $f ];
}
} else {
echo "没有上传任何文件";
}
echo" </td>
</tr>
</table>
</div>";
$con = mysqli_connect( "localhost", "root", "" );
if ( !$con ) {
die( 'Could not connect: ' . mysqli_error() );
} else {
echo "connect!<br/>";
}
// Create database
// Create table in my_db database
if ( mysqli_query( $con, 'set names utf8' ) ) {
echo "set char";
} else {
echo "fail:set char" . mysqli_error( $con );
}
echo "<br>";
if ( mysqli_select_db( $con, "test" ) ) {
echo( "choose database test<br/>" );
}
if ( mysqli_query( $con, "select * from information_schema.tables where table_schema='test' and table_name='selltest'")) {
echo "selltest 已创建";
mysqli_error( $con );
} else {
$ct = "create table selltest
(
商品属性 text(20),
商品描述 text(40),
姓名 varchar(15),
电话 bigint(11),
wechat text(30),
邮箱 text(30),
身份 int(1),
id int auto_increment primary key not null
)";
if ( mysqli_query( $con, $ct ) ) {
echo "<br/>成功创建表单";
} else {
echo " <br/>no success创建表单" . mysqli_error( $con );
}
}
$ins = "insert into selltest(商品名,商品属性,商品描述,姓名,电话,wechat,邮箱,身份,用户)
values('$shopname','$c','$w','$n','$p','$wc','$e','$i','$s')";
if ( mysqli_query( $con, $ins ) ) {
echo "success insert";
} else {
echo "fail:to insert" . mysqli_error( $con );
}
echo "<br/>";
mysqli_close( $con );
?>
</body>
<script>
function jump(){
location.href="../index.php";
}
setTimeout(jump,5000);
</script>
</html>
转载:https://blog.csdn.net/BO688/article/details/102012296
查看评论