在foreach循环中形成不会POST

时间:2014-01-29 20:54:23

标签: php forms foreach

出于某种原因,我似乎无法解决这个问题,我知道我之前已经解决了这个问题但却记不起来了。我在数据库中有一组数据。我使用foreach从数据库中提取每一行,以便我可以编辑它们。

然后在foreach标签中我有一个包含数据的表单,所以我可以编辑它,一旦我完成,我可以点击编辑,这个想法就是那个特定数据集的形式通过函数和编辑id = $id ...

行的数据

就像我说我之前已经解决了这个问题,但对于我的生活,我不知道这次要做什么。任何人都可以提出任何建议,我没有发布任何代码,因为我不知道是否需要它,它似乎很简单,一个表单以及如何让它从foreach循环中发送单个表单,但我可以如果需要,提供代码。

foreach中的表格

$marquee = live_news_for_marquee($headline, $type);
foreach ($marquee as $headline) {
?>
<form action="" method="POST">
    <td><input name="id" type="text" class="" style="width:10px;" value="<?php echo $headline['id']; ?>" disabled="disabled"></td>
    <td><textarea name="update_headline" id="" cols="30" rows="10"><?php echo $headline['headline']; ?></textarea></td>
    <td><?php echo date('d/m/Y H:i:s', $headline['date']); ?></td>
    <td>
        <select name="update_type" id="">
            <option value="<?php echo $headline['type']; ?>"><?php echo $headline['type']; ?></option>
            <option value="BreakingNews">Breaking News</option>
            <option value="Standard">Standard News</option>
        </select>
    </td>

    <td><input type="checkbox" name="live" value="1" <?php if ($headline['live'] == 1) {echo "checked=\"checked\"";} ?>>Live <br>
        <input type="checkbox" name="live" value="0" <?php if ($headline['live'] == 0) {echo "checked=\"checked\"";} ?>>Off </td>
    <td><button class="btn red_btn">Edit</button></td>
</form>
<?php
;}
?>

这里有更多与已经提供的代码相关联的代码..这第一个代码来自页面顶部,我处理POST信息..我已经乱搞了很多次因为信息刚刚没有似乎是POST所以我根本无法做任何事情......

if (isset($_POST['id']) && isset($_POST['update_headline']) && isset($_POST['update_type']) && isset($_POST['live'])) {
$errors = array();

$update_id = (int)$_POST['id'];
$update_headline = mysql_real_escape_string($_POST['update_headline']);
$update_type = mysql_real_escape_string($_POST['update_type']);
$live = (int)$_POST['live'];

if (empty($update_id)) {
    $errors[] = 'Theres something that went wrong!';
}
if (empty($update_headline)) {
    $errors[] = 'You need a headline before you send this!';
}
if (empty($update_type)) {
    $errors[] = 'You need to give this entry a "type of entry"!';
}
if (empty($live)) {
    $errors[] = 'You need to select if this headline will be live on the site, or not and stored in the db!';
}

if (!empty($errors)) {
    echo output_errors($errors);
} else {
    edit_news($update_id, $update_headline, $update_type, $live);
    ?>
<br><br>
        <div class="success_msg"><p>The Headline News has been modified successfully.</p></div> 
    <?php
}

}

2 个答案:

答案 0 :(得分:2)

尝试使用以下格式添加新按钮:

<input type='submit' value='Submit'>

还要确保包含引号。没有它们就行不通。

答案 1 :(得分:0)

<button>更改为<submit><input type=submit>。点击后<button>不会触发提交。

相关问题