Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PHP输入类型radio中的不同名称_Php - Fatal编程技术网

通过PHP输入类型radio中的不同名称

通过PHP输入类型radio中的不同名称,php,Php,我有一个foreach代码,可以从数据库中读取主题。我希望它们可以写入另一个数据库classic$_POST[];方法 我的foreach代码看起来像 <form action="" method="post"> <?php foreach ($articles as $article) { ?> <input type="radio" name="<?php $article['tema_id']; ?>"> &l

我有一个foreach代码,可以从数据库中读取主题。我希望它们可以写入另一个数据库classic$_POST[];方法 我的foreach代码看起来像

<form action="" method="post">
   <?php foreach ($articles as $article) { ?>
     <input type="radio" name="<?php $article['tema_id']; ?>"> 
       <?php echo $article['nazov_temy']; ?> <small> - <?php echo $article['obsah_temy']; ?></small><br />
       <?php } ?>
     <input type="submit" name="odoslat" />
</form>
根据你上面的评论 HTML

如果只想选择一个主题并将其传递到下一个PHP处理器页面。为使用foreach循环生成的所有无线电元素输入一个公共名称

例如:上面的Foreach循环将生成如下HTML元素

<input type="radio" name="selected_theme" value="1"> 
<input type="radio" name="selected_theme" value="2"> 
<input type="radio" name="selected_theme" value="3"> 
.........

您是否只将$article['tema_id']的一个值传递给DB??我可以看到$article['tema_id']是名称,但是如果您只选择了一个值并将其传递给DB,请使用公共名称和使用框来选择一个值。是否要一次向DB发送多篇文章?若要基于名称获取值,您应该为任何类型的输入字段使用静态名称或逗号名称。我需要使用radio,因为用户应该只选择一个主题,主题应该写入数据库。我需要将整个nazov_temy发布到数据库中,我只知道一种方法基于表单中的名称
//Inside foreach
<input type="radio" name="selected_theme" value="<?php $article['tema_id']; ?>"> 
$theme = $_POST['selected_theme'];
<input type="radio" name="selected_theme" value="1"> 
<input type="radio" name="selected_theme" value="2"> 
<input type="radio" name="selected_theme" value="3"> 
.........
<select name='selected_theme'>
      <?php foreach....... ?>
      <option value="<?php $article['tema_id']; ?>">Theme name</option>
       ......
</select>
$selected_theme_id = $_POST['selected_theme'];