Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.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-HTML使用input=文本更新mysql,其中POST[';提交';]_Php_Html_Mysql_Validation_Post - Fatal编程技术网

PHP-HTML使用input=文本更新mysql,其中POST[';提交';]

PHP-HTML使用input=文本更新mysql,其中POST[';提交';],php,html,mysql,validation,post,Php,Html,Mysql,Validation,Post,我想从速递公司打电话。 我使用HTML格式的foreach,MySQL表,调用状态为“1”,因此我可以看到仍然需要调度witch调用 当我在输入文本中输入'MessagerID'并按下'Dispatch'按钮时,我希望此'CourseID'用'MessengerID'更新,并且'Status'变为'0' 这里有一点代码。(还没有健全…) HTML格式: <?php foreach($Courses as $Course) { echo '<tr>';

我想从速递公司打电话。 我使用HTML格式的foreach,MySQL表,调用状态为“1”,因此我可以看到仍然需要调度witch调用

当我在输入文本中输入'MessagerID'并按下'Dispatch'按钮时,我希望此'CourseID'用'MessengerID'更新,并且'Status'变为'0'

这里有一点代码。(还没有健全…)

HTML格式:

    <?php foreach($Courses as $Course)
    {
    echo '<tr>';
    echo '<td><input type="text" name="'. $Course['ID'] . '" value="' . $Course['ID'] . '"</td>';
    echo '<td><input type="text" name="CourseRecu" value="' . $Course['CourseRecu'] . '"/></td>';
    echo '<td><textarea rows="3" cols="50" name="Depart">' . $Course['DepNom'] . '&#13;&#10;' . $Course['DepAdresse'] . '</textarea></td>';
    echo '<td>----></td>';
    echo '<td><textarea rows="3" cols="50" name="Destination">' . $Course['DestNom'] . '&#13;&#10;' . $Course['DestAdresse'] .  '</textarea></td>';
    echo '<td>
            <input type="text" name="MessagerID' . $Course['ID'] .'" value="' . $Course['MessagerID'] . '" /></td>';

    echo '<td><input type="submit" name="submit' . $Course['ID'] . '" value="Dispatch" /></td>';

    echo '</tr>';
    }
我想我可能一路上都走错了方向,也许有更好的方法。。。
谢谢你抽出时间!:-)

我将提出一些修改建议

1) 在与特定课程相对应的每组输入字段周围填写表格,例如:

<?php foreach($Courses as $Course)
{
echo '<tr><form>';
echo '<td>


编辑:重命名提交的方法同样适用于其他输入字段

你从哪里得到$Course?是的!“foreach”中的“”效果很好!我就在不远处,我明白了。。。我真的很感谢你花了这么多时间,谢谢你!
    if(!empty($_POST['submit' . $Course['ID']]))
{
    $query = "UPDATE courses SET 
            MessagerID = :MessagerID,
            Status = :Status
            WHERE ID = :ID" ;   
    $query_params = array(
    ':MessagerID' => $_POST['MessagerID' . $Course['ID']],
    ':Status' => 0,
    ':ID' => $_POST[$Course['ID']]); 

    try 
        { 
            // Execute the query to create the user 
            $stmt = $db->prepare($query); 
            $result = $stmt->execute($query_params); 
        } 
        catch(PDOException $ex) 
        {
            die("La requête à échoué: " . $ex->getMessage()); 
        }
}
<?php foreach($Courses as $Course)
{
echo '<tr><form>';
echo '<td>
 echo '<input type="hidden" name="id" value="'. $Course['ID'].' />";
 echo '<td><input type="submit" name="submit" value="Dispatch" /></td>';

echo '</form></tr>';
if (!empty($_POST['submit']) && !empty($_POST['id'])
   $CourseID = $_POST['id'];
   //Do what you need to do to get the course here.