【php开源代码栏目提醒】:网学会员php开源代码为您提供add_apply.php参考,解决您在add_apply.php学习中工作中的难题,参考学习。
<?php
// 包含数据库连接文件
require ('dbconnect.php');
?>
<?
// 取得网页的参数
$username=$_POST['username'];
$email=$_POST['email'];
$select=$_POST['select'];
$title=$_POST['title'];
$choice=$_POST['choice'];
// 取得当前时间和日前
$now = date("Y-m-d H:i:s");
// 投票主题写入数据库表title
$titlesql="insert into title (username, email, title, types, choice, times) values('$username', '$email', '$title', '$select', '$choice', '$now')";
mysql_query($titlesql,$conn) or die ("插入数据失败: ".mysql_error());
// 使用Last_insert_ID()函数获得最近自动产生的序列编号
$result=my
sql_query("select last_insert_id()",$conn);
$re_arr=
mysql_fetch_array($result);
$titleid=$re_arr[0];
// 拆分投票选项
$info=split('#',$choice);
// 将投票选项写入vote表
for($i=0;$i<count($info);$i++){
$choicesql="insert into vote(titleid, info, vcount) values('$titleid', '$info[$i]', '0')";
mysql_query($choicesql,$conn);
}
// 关闭连接
mysql_close($conn);
//print "Good";
// 重定向到browse.php页面,显示投票主题
header("Location:browse.php");
?>