请教一个简单的投票页面,post怎么写

bluesjunior bluesjunior 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以前写过一个简单的投票功能,作用是php post值 如果和数据库内容一致,则count+1 截图如下
<form method="post" action="check.php"> 
<input type="text" name="test">

<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>

<?php
$conn = mysql_connect("127.0.0.1:8889","root","root");
$action = $_POST['action'];
if($action == 'send'){
$test = $_POST['test'];

mysql_select_db("test3",$conn);
$sql = ("update tll set count=count+1 where tl01='$test'");
$result = mysql_query($sql,$conn);
}
?>


现在希望把check.php由原来的单个框改成多个进行投票 网上查了下,要用到数组 我把代码改成

<form method="post" action="check.php">
<input type="text" name="test[]"> <br />
<input type="text" name="test[]"> <br />
<input type="text" name="test[]"> <br />
<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>

<?php
$conn = mysql_connect("127.0.0.1:8889","root","root");
$action = $_POST['action'];
if($action == 'send'){
$test = $_POST['test[]'];

mysql_select_db("test3",$conn);
$sql = ("update tll set count=count+1 where tl01='$test'");
$result = mysql_query($sql,$conn);
}
?>
的话就完全行不通了 ,实在不懂,请大神帮忙看下改下代码,十分感谢!

再问下,数据库的格式是“1空格1空格1” 这个格式是固定的
投票页面 如果投票成功,数据库的count的确+1的话echo投票成功,如果不成功(比如格式错了,或者填写错误)echo
投票失败,,这个怎么做呢?90分献上,望指教!
...全文
评论 6
收藏 已收藏
分享
返回顶部
bluesjunior
基础编程 21,889 成员 140,329 内容