通过表单

时间:2017-09-04 12:11:37

标签: php html

我有以下代码,变量'name'和'project'需要在提交时转到会话变量,在这种情况下,提交通过'onchange'event进行。 'name'变量是POSTed但不是'project'变量。我的问题是什么想法?

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<?php
$query = $conn->prepare("SELECT name, project FROM models.models where models.active = 'yes'");
$query->execute();
while($r = $query->fetch(PDO::FETCH_OBJ)){

echo "
<div class='swiper-slide'>
  <input type='image' src='models/thumbs/",$r->name,".jpg' id='name' name='name' value='",$r->name,"' onchange='this.form.submit();'/>
  <input type='hidden' value='",$r->project,"' name='project' />
</div>

";
}

?>
</form>

1 个答案:

答案 0 :(得分:-1)

<?php
$query = $conn->prepare("SELECT name, project FROM models.models where models.active = 'yes'");

$query->execute();
while($r = $query->fetch(PDO::FETCH_OBJ)){

echo "
<div class='swiper-slide'>
  <input type='image' src='models/thumbs/",$r->name,".jpg' id='name' name='name[]' value='",$r->name,"' onchange='this.form.submit();'/>
  <input type='hidden' value='",$r->project,"' name='project' />
</div>

";

}

?>

如何访问:

$names = $_POST['name'];

for($i=0;$i<count($names);$i++)
{
   echo $names[$i]."<br>";
}