无法使用php更新多行

时间:2015-08-07 08:46:04

标签: php

任何人都可以帮我处理我的案例......为什么无法更新我的数据 我是php和mysql的新手。我不知道该怎么做。我坚持这个。 请参考示例。该怎么办?

PHP

<?php require_once("include/connection.php")?>

<?php
$group_id = (int)$_GET['id']; 
    if(isset($_POST['submit'])) {

            $hour_start = $_POST['hour_start'];
            $minute_start = $_POST['minute_start'];
        $time_start = $hour_start . ":" . $minute_start;
            $hour_finish = $_POST['hour_finish'];
            $minute_finish = $_POST['minute_finish'];
        $time_finish = $hour_finish . ":" . $minute_finish;
        $day_start = $_POST['day_start'];
        $day_finish = $_POST['day_finish'];



            $query2 = "UPDATE test_group_details SET 
                    time_start = '{$time_start}', 
                    time_finish = '{$time_finish}', 
                    day_start = '{$day_start}', 
                    day_finish = '{$day_finish}', 
                    hour_start = '{$hour_start}', 
                    minute_start = '{$minute_start}', 
                    hour_finish = '{$hour_finish}', 
                    minute_finish = '{$minute_finish}' 
                    WHERE id = '{$details_id }'                         
                    ";
            $result2 = mysql_query($query2, $connection);

    /* }  */
} 
?> 

这是显示数据的地方......还有要更新的表格.. 的 HTML

<div class="nav_left">
    <form name="frm" action="#" method="post" onsubmit="return frm_onsubmit();">
        <table>
            <tbody>

                <tr>
                    <?php
                    $edit_query2 = "SELECT * FROM test_group_details WHERE group_id = '{$group_id}' ";                  
                    $rs2 = mysql_query($edit_query2,$connection);
                    while($row2 = mysql_fetch_array($rs2)):

                    ?>  
                    <td colspan="2"><h5><?php echo "\n\n" . $row2['time_start'] . " - " . $row2['time_finish'] . " ["  . $row2['day_start'] . " - " . $row2['day_finish'] . "] ";?><hr></h5>

                    <input type="text" name="id" value="<?php echo $row2['id'];?>">

                    </td>
                </tr>
                <tr><td colspan="2">
                        <table>
                        <tbody>
                        <tr>
                            <td>Time to start:</td>
                            <td>
                                <select name="hour_start[]">
                                <option value="<?php echo $row2['hour_start'] ;?>" selected=""><?php echo $row2['hour_start'] ;?></option>
                                <option value="01"> 01</option><option value="02"> 02</option><option value="03"> 03</option><option value="04"> 04</option><option value="05"> 05</option><option value="06"> 06</option><option value="07"> 07</option><option value="08"> 08</option><option value="09"> 09</option><option value="10"> 10</option><option value="11"> 11</option><option value="12"> 12</option><option value="13"> 13</option><option value="14"> 14</option><option value="15"> 15</option><option value="16"> 16</option><option value="17"> 17</option><option value="18"> 18</option><option value="19"> 19</option><option value="20"> 20</option><option value="21"> 21</option><option value="22"> 22</option><option value="23"> 23</option><option value="24"> 24</option>
                                </select>&nbsp:&nbsp
                                <select name="minute_start[]">
                                <option value="<?php echo $row2['minute_start'] ;?>" selected=""> <?php echo $row2['minute_start'] ;?></option>
                                <option value="01"> 01</option><option value="02"> 02</option><option value="03"> 03</option><option value="04"> 04</option><option value="05"> 05</option><option value="06"> 06</option><option value="07"> 07</option><option value="08"> 08</option><option value="09"> 09</option><option value="10"> 10</option><option value="11"> 11</option><option value="12"> 12</option><option value="13"> 13</option><option value="14"> 14</option><option value="15"> 15</option><option value="16"> 16</option><option value="17"> 17</option><option value="18"> 18</option><option value="19"> 19</option><option value="20"> 20</option><option value="21"> 21</option><option value="22"> 22</option><option value="23"> 23</option><option value="24"> 24</option><option value="25"> 25</option><option value="26"> 26</option><option value="27"> 27</option><option value="28"> 28</option><option value="29"> 29</option><option value="30"> 30</option><option value="31"> 31</option><option value="32"> 32</option><option value="33"> 33</option><option value="34"> 34</option><option value="35"> 35</option><option value="36"> 36</option><option value="37"> 37</option><option value="38"> 38</option><option value="39"> 39</option><option value="40"> 40</option><option value="41"> 41</option><option value="42"> 42</option><option value="43"> 43</option><option value="44"> 44</option><option value="45"> 45</option><option value="46"> 46</option><option value="47"> 47</option><option value="48"> 48</option><option value="49"> 49</option><option value="50"> 50</option><option value="51"> 51</option><option value="52"> 52</option><option value="53"> 53</option><option value="54"> 54</option><option value="55"> 55</option><option value="56"> 56</option><option value="57"> 57</option><option value="58"> 58</option><option value="59"> 59</option>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td>Time to finish:</td>
                            <td>
                                <select name="hour_finish[]">
                                <option value="<?php echo $row2['hour_finish'] ;?>" selected=""><?php echo $row2['hour_finish'] ;?></option>
                                <option value="01"> 01</option><option value="02"> 02</option><option value="03"> 03</option><option value="04"> 04</option><option value="05"> 05</option><option value="06"> 06</option><option value="07"> 07</option><option value="08"> 08</option><option value="09">09</option><option value="10"> 10</option><option value="11"> 11</option><option value="12"> 12</option><option value="13"> 13</option><option value="14"> 14</option><option value="15"> 15</option><option value="16"> 16</option><option value="17"> 17</option><option value="18"> 18</option><option value="19"> 19</option><option value="20"> 20</option><option value="21"> 21</option><option value="22"> 22</option><option value="23"> 23</option><option value="24"> 24</option>
                                </select>&nbsp:&nbsp

                                <select name="minute_finish[]">
                                <option value="<?php echo $row2['minute_finish'] ;?>" selected=""> <?php echo $row2['minute_finish'] ;?></option>
                                <option value="01"> 01</option><option value="02"> 02</option><option value="03"> 03</option><option value="04"> 04</option><option value="05"> 05</option><option value="06"> 06</option><option value="07"> 07</option><option value="08"> 08</option><option value="09">09</option><option value="10"> 10</option><option value="11"> 11</option><option value="12"> 12</option><option value="13"> 13</option><option value="14"> 14</option><option value="15"> 15</option><option value="16"> 16</option><option value="17"> 17</option><option value="18"> 18</option><option value="19"> 19</option><option value="20"> 20</option><option value="21"> 21</option><option value="22"> 22</option><option value="23"> 23</option><option value="24"> 24</option><option value="25"> 25</option><option value="26"> 26</option><option value="27"> 27</option><option value="28"> 28</option><option value="29"> 29</option><option value="30"> 30</option><option value="31"> 31</option><option value="32"> 32</option><option value="33"> 33</option><option value="34"> 34</option><option value="35"> 35</option><option value="36"> 36</option><option value="37"> 37</option><option value="38"> 38</option><option value="39"> 39</option><option value="40"> 40</option><option value="41"> 41</option><option value="42"> 42</option><option value="43"> 43</option><option value="44"> 44</option><option value="45"> 45</option><option value="46"> 46</option><option value="47"> 47</option><option value="48"> 48</option><option value="49"> 49</option><option value="50"> 50</option><option value="51"> 51</option><option value="52"> 52</option><option value="53"> 53</option><option value="54"> 54</option><option value="55"> 55</option><option value="56"> 56</option><option value="57"> 57</option><option value="58"> 58</option><option value="59"> 59</option>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td>Week Day Start:</td>
                            <td>
                                <select name="day_start[]">
                                <option value="<?php echo $row2['day_start'] ;?>"><?php echo $row2['day_start'] ;?></option><option value="Monday">Monday</option><option value="Tuesday">Tuesday</option><option value="Wednesday">Wednesday</option><option value="Thursday">Thursday</option><option value="Friday">Friday</option><option value="Saturday">Saturday</option><option value="Sunday">Sunday</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>Week Day finish:</td>
                            <td>
                                <select name="day_finish[]">
                                <option value="<?php echo $row2['day_finish'] ;?>"><?php echo $row2['day_finish']; ?></option><option value="Monday">Monday</option><option value="Tuesday">Tuesday</option><option value="Wednesday">Wednesday</option><option value="Thursday">Thursday</option><option value="Friday">Friday</option><option value="Saturday">Saturday</option><option value="Sunday">Sunday</option>
                                </select>
                            </td>
                        </tr>
                        <?php echo "\n"; endwhile;?> 
                        </tbody>
                        </table>
                    </td>
                </tr>   
                <tr>
                    <td colspan="2"><h6><input name="submit" tabindex="1" value="Update" type="submit" onclick="validate()"></h6>
                    </td>
                </tr>
            </tbody>
        </table><!-- end of table frm_timegroups -->
    </form>
</div>

请帮助我们......是他们的一种方式......?

1 个答案:

答案 0 :(得分:0)

您在代码中定义了哪些$details_id

我看不到它。我只看到$group_id,无论如何都是单号。

db中的行是否与group_id相同?

表格中该字段的名称是什么?