<?php session_start(); include("../conn/conn.php"); 
if ($Submit=="单选" and $_FILES['tb_vote_photo']['name']==""){		//判断是单选，并且没有图片上传
	//执行将数据添加到单选数据表中
	$query="insert into tb_vote_odd(tb_vote_subject,tb_vote_content,tb_vote_counts,tb_vote_type,tb_vote_explain)values('$_POST[tb_vote_subject]','$_POST[tb_vote_content]','0','$Submit','$_POST[tb_vote_explain]')";
	$result=mysql_query($query);
	if ($result){
		echo "<script>alert('投票内容提交成功!');window.location.href='index.php?admin_title=管理投票内容';</script>";
	}else{echo "失败!";}
}

if ($Submit=="单选" and $_FILES['tb_vote_photo']['name']!=""){	//判断是单选，并且有图片上传
	$tb_vote_photo=$_FILES['tb_vote_photo']['size'];		//获取图片大小
	$tb_vote_photo_name=$_FILES['tb_vote_photo']['name']; //获取客户端机器原文件的名称
	$tb_vote_photo_type=strtolower(strstr($tb_vote_photo_name,".")); //获取从"."到最后的字符,并将字符转换成小写
	if($tb_vote_photo>2000000){		//判断图片是否超过指定大小
		echo "<script>alert('对不起,您上传的图片超过2M!');history.back();</script>";
	}else{
		//判断上传图片的后缀名是否符合
		if($tb_vote_photo_type!=".jpg" & $tb_vote_photo_type!=".gif" & $tb_vote_photo_type!=".bmp" & $tb_vote_photo_type!=".jpeg"){
			echo "<script>alert('对不起,您上传的图片的格式不正确!');history.back();</script>";
		}else{
			//定义图片在服务器中的存储路径
			$tb_vote_photo_path='../images/photo/'.date("YmdHis").mt_rand(1000000,9999999).$_FILES['tb_vote_photo']['name'];
			//应用move_uploaded_file函数，将图片存储到指定的文件夹下
			if(move_uploaded_file($_FILES['tb_vote_photo']['tmp_name'],$tb_vote_photo_path)){
				//执行添加语句，将数据添加到单选表中
				$query="insert into tb_vote_odd(tb_vote_subject,tb_vote_content,tb_vote_counts,tb_vote_type,tb_vote_explain,tb_vote_photo)values('$_POST[tb_vote_subject]','$_POST[tb_vote_content]','0','$Submit','$_POST[tb_vote_explain]','$tb_vote_photo_path')";
				$result=mysql_query($query);
				if ($result){
					echo "<script>alert('投票的内容提交成功!');window.location.href='index.php?admin_title=管理投票内容';</script>";
				}else{
					echo "失败!";
				}
				
			}			
		}
	}
}

if ($Submit2=="多选" and $_FILES['tb_vote_photo']['name']==""){	//判断提交按钮的值是多选，并且无图片上传
	$query="insert into tb_vote_more(tb_vote_subject,tb_vote_content,tb_vote_counts,tb_vote_type,tb_vote_explain)values('$_POST[tb_vote_subject]','$_POST[tb_vote_content]','0','$Submit2','$_POST[tb_vote_explain]')";
	$result=mysql_query($query);
	if ($result){
		echo "<script>alert('投票内容提交成功!');window.location.href='index.php?admin_title=管理投票内容';</script>";
	}else{echo "失败!";}
}


if ($Submit2=="多选" and $_FILES['tb_vote_photo']['name']!=""){
	$tb_vote_photo=$_FILES['tb_vote_photo']['size'];
	$tb_vote_photo_name=$_FILES['tb_vote_photo']['name']; //获取客户端机器原文件的名称
	$tb_vote_photo_type=strtolower(strstr($tb_vote_photo_name,".")); //获取从"."到最后的字符,并将字符转换成小写
	if($tb_vote_photo>2000000){
		echo "<script>alert(对不起,您上传的图片超过2M!);history.back();</script>";
	}else{
		if($tb_vote_photo_type!=".jpg" & $tb_vote_photo_type!=".gif" & $tb_vote_photo_type!=".bmp"){
			echo "<script>alert(对不起,您上传的图片的格式不正确!);history.back();</script>";
		}else{
			$tb_vote_photo_path='../images/photo/'.date("YmdHis").mt_rand(1000000,9999999).$_FILES['tb_vote_photo']['name'];
			if(move_uploaded_file($_FILES['tb_vote_photo']['tmp_name'],$tb_vote_photo_path)){
				$query="insert into tb_vote_more(tb_vote_subject,tb_vote_content,tb_vote_counts,tb_vote_type,tb_vote_explain,tb_vote_photo)values('$_POST[tb_vote_subject]','$_POST[tb_vote_content]','0','$Submit2','$_POST[tb_vote_explain]','$tb_vote_photo_path')";
				$result=mysql_query($query);
				if ($result){
					echo "<script>alert('投票内容提交成功!');window.location.href='index.php?admin_title=管理投票内容';</script>";
				}else{
					echo "失败!";
				}
				
			}			
		}
	}
}






?>
