dongxietao0263 2015-04-06 22:46
浏览 14
已采纳

使用php问题的数组数据

here is my code the part of the option in php is not working somehow and it will only print team and question only when i tested

<?php
 Include("conifdata.php");

$command= "INSERT INTO SoccerPoll (Team, Question, Player1, Player2, Player3, Player4) VALUES (?,?,?,?,?,?)";
$stmt = $dbh ->prepare($command);
$stmt->execute(array($_POST['team'], $_POST['question'],$_POST['option[0]'], $_POST['option[1]'], $_POST['option[2]'], $_POST['option[3]']));
if($stmt ->rowCount()>0){
    echo "Successfull";
}

// when tested here it will only print team and question only i need all of them

 echo $_POST["team"], $_POST['question'], $_POST['option[0]'], $_POST['option[1]'], $_POST['option[2]'], $_POST['option[3]'];



 //and here is my html page

<h1>Create a Team Poll</h1>
<p>enter data.</p>
<form action="addPoll.php" method="POST">
Team: <input type="text" required name="team"><br>
Question: <input type="text" required name="question"><br>
Option 1: <input type="text" required name="option1"><br>
Option 2: <input type="text" required name="option2"><br>
Option 3: <input type="text" required name="option[]"><br>
Option 4: <input type="text" required name="option[]"><br>
<input type="submit" value="Create Poll">
</form>
  • 写回答

2条回答 默认 最新

  • dor65412 2015-04-06 22:54
    关注

    When a parameter name ends with [...], that isn't part of the $_POST key, it causes that $_POST variable to be a sub-array. You need to access it with multi-dimensional array syntax. So $_POST['option[0]'] should be $_POST['option'][0], and similarly for all the other elements of that array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 dify知识库创建问题
  • ¥15 如何用C#的chart画1000万个点不卡顿
  • ¥15 爬虫技术找到网上看过房源客户的电话
  • ¥20 代码:Python随机森林反演生物量数据处理问题
  • ¥50 微信野豹球杆小程序数据
  • ¥15 Linux系统的命令行窗口回车变成了换行,无法执行命令了
  • ¥15 vb6.0调用ImageMagick进行图片转换问题
  • ¥15 安卓组件化工程引入Arouter报错there's no route matched path[/login/LoginActivity,如何解决?
  • ¥50 如何进行点云姿态调整优化
  • ¥20 关于c++的问题 如何用qt完成