简体   繁体   English

在foreach循环中形成不会POST

[英]form inside a foreach loop wont POST

For what ever reason I just cant seem to work this out, I know I've solved this before but can't remember how. 出于某种原因,我似乎无法解决这个问题,我知道我之前已经解决了这个问题但却记不起来了。 I have a set of data in a database. 我在数据库中有一组数据。 I use a foreach to pull each row from the database so I can edit them. 我使用foreach从数据库中提取每一行,以便我可以编辑它们。

Then in the foreach tag I have a form with the data set out so I can edit it and once I'm done I can click edit and the idea is the form for that specific set of data would go through the function and edit data on the row where id = $id ... 然后在foreach标签中我有一个包含数据的表单,所以我可以编辑它,一旦我完成,我可以点击编辑,这个想法就是那个特定数据集的形式将通过函数和编辑数据id = $id的行...

Like I said I've solved this issue before but for the life of me I cant work out what to do this time round. 就像我说的那样,我之前已经解决了这个问题,但对于我的生活,我不知道这次要做什么。 Can anyone suggest anything, I've not posted any code as I don't know if it's needed, it seems simple, a form and how to get it to send individual forms from within a foreach loop, but I can provide code if needed. 任何人都可以提出任何建议,我没有发布任何代码,因为我不知道它是否需要,它看起来很简单,一个表单以及如何让它从foreach循环中发送单个表单,但我可以提供代码,如果需要。

The form within the 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
;}
?>

Here is more code that is associated with the code already provided.. this first code is from the top of the page, where i process the POST info.. I have messed around with it plenty of times because the info just didn't seem to POST so i couldn't do anything at all.. 这里有更多的代码与已经提供的代码相关联..这个第一个代码来自页面的顶部,我在那里处理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
}

}

Try adding a new button using this exact format: 尝试使用以下格式添加新按钮:

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

Also be sure to include the quotes. 另外一定要包括引号。 It won't work without them. 没有它们就行不通。

Change the <button> to a <submit> or <input type=submit> . <button>更改为<submit><input type=submit> <button> won't trigger submission when clicked. 单击时, <button>不会触发提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM