首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >HTML表单在一定数量的条目后不更新信息

HTML表单在一定数量的条目后不更新信息
EN

Stack Overflow用户
提问于 2016-08-01 09:26:13
回答 1查看 42关注 0票数 0

下面是一个页面上的所有PHP脚本。直到我的一个用户遇到问题,这个页面才能正常工作。他们给我发消息,说编辑功能不再起作用了。通常,当你点击“更新”时,你会看到一条消息,告诉你你的愿望列表已经被更新了,但是对于这个用户来说,当他们点击“更新”按钮时,它只是刷新了页面。它不再更改数据库中的信息。

我尝试从数据库中删除一些条目,然后用户就可以进行编辑了。一旦他们重新添加了这些生物,它就不再起作用了,事实上它是在一个不同的位置中断的。

第一次愿望列表更新功能打破了大约162个生物,这次它打破了大约168个生物。

是什么导致了这个奇怪的小故障呢?我能做些什么来修复它?谢谢!

代码语言:javascript
复制
   <center>
      <code>
        [insert_php]
        // Info to connect to the Wishlist database
        $servername = "secret";
        $dbusername = "secret";
        $password = "supersecret";
        $dbname = "notsosecret";

        try {
            // To connect to the database please
            $conn = new mysqli($servername, $dbusername, $password, $dbname);
            if ($conn->connect_error) {
                die('Connect Error (' . $conn->connect_errno . ') '
                    . $conn->connect_error);
            }

           echo "<font size ='3'><br>Please click <strong><a href = 'http://eggcavity.com/add-wishlist'>here</a></strong> to add creatures to your wishlist.<br><br>Please click <strong><a href='http://eggcavity.com/wishlists'>here</a></strong> to view your wishlist.<br><br>At the moment when you enter notes you cannot view them on the edit page. <br>Please go to the view wishlist page to see your notes.<br><br></font>";

           if(isset($_POST['submit'])){
                $ids = $_POST['ids'];
                $theCount = 0;
                // Prepare and bind the udpate statement
                $sql2 = "UPDATE Wishlists SET Picture = ?, Stage = ?, Gender = ?, Frozen = ?, Notes= ? WHERE ID = ?";
                $stmt2 = $conn->prepare($sql2);
                $stmt2->bind_param('sssssi', $picture, $stage, $gender, $frozen, $notes, $id);
                foreach($ids as $id){
                    $stagecode = $id . "stage";
                    $gendercode = $id . "gender";
                    $frozencode = $id . "frozen";
                    $notescode = $id . "notes";
                    $namecode = $id . "creature";
                    $stage = $_POST[$stagecode];
                    $Stage = $stage;
                    $gender = $_POST[$gendercode];
                    $frozen = $_POST[$frozencode];
                    $notes = $_POST[$notescode];
                    $name = $_POST[$namecode];
                    $sql1 = 'SELECT * FROM Creatures WHERE Name = "' . $name . '"';
                    $result = mysqli_query($conn, $sql1);
                    $row = $result->fetch_assoc();
                    $picture = $row["$stage"];
                    $stmt2->execute();
                }
                if(isset($_POST['delete'])) {
                    $delete=!empty( $_POST['delete'] ) ? $_POST['delete'] : false;
                    if($delete && !is_array($delete) ){
                        $delete=explode(',',$delete);
                    }
                    foreach($delete as $id){
                        $sql = "DELETE FROM Wishlists WHERE ID = ?";
                        $stmt = $conn->prepare($sql);
                        $stmt->bind_param('i', $id);
                        $stmt->execute();
                        $theCount++;
                     }
                 }
                 echo "<font size='3'>Your wishlist has been updated, and " .$theCount. " creature(s) has/have been removed from your wishlist.<br><br>Please click <u><strong><a href='http://eggcavity.com/edit-wishlist'>here</a></u></strong> to return to the edit page.</href><br><br>";
           } else {
               // Get current user's username
               $current_user = wp_get_current_user();
               $username = $current_user->user_login;
               // Just display the form
               $sql = 'SELECT Creature, Picture, Stage, Gender, Frozen, Notes, ID FROM Wishlists WHERE Username = "' . $username . '"';
               $result = mysqli_query($conn, $sql);
               if (mysqli_num_rows($result) > 0) {
                   $numcreatures = mysqli_num_rows($result);
                   echo '<form method="POST"><table style="border-collapse: collapse";><strong>' .
                       '<tr>' .
                           '<td>' . $numcreatures . ' creatures</td>' .
                           '<td style="border:1px solid gray;text-align:center;">Creature</td>' .
                           '<td style="border:1px solid gray;text-align:center;">Stage</td>' .
                           '<td style="border:1px solid gray;text-align:center;">Gender</td>' .
                           '<td style="border:1px solid gray;text-align:center;">Frozen</td>' .
                       '</tr></strong>';
                   while($row = $result->fetch_assoc()) {
                       $creature = $row["Creature"];
                       $id = $row["ID"];
                       $picture = $row["Picture"];
                       $stage = $row["Stage"];
                       $sql3 = 'SELECT * FROM Creatures WHERE Name = "' . $creature . '"';
                       $result2 = mysqli_query($conn, $sql3);
                       $row2 = $result2->fetch_assoc();
                       echo '<input name="ids[]" type="hidden" value="' . $id . '">' .
                           '<input name="' . $id . 'creature" type="hidden" value="' . $creature . '">' .
                           '<tr>' .
                               '<td rowspan="2" style="border:1px solid gray;text-align:center;"><img src="' . $picture . '"></td>' .
                               '<td style="border:1px solid gray;text-align:center;">' . $creature . '</td>' .
                               '<td style"border:1px solid gray;text-align:center;"><select name="' . $id . 'stage">' .
                                   '<option value ="' . $stage . '" selected>' . $stage . '</option>' . 
                                   '<option value = "Stage1">Stage1(Egg)</option>' .
                                   '<option value = "Stage2">Stage2</option>';
                                   if ($row2["Stage3"] != "") {
                                       echo '<option value = "Stage3">Stage3</option>';
                                   }
                                   if ($row2["Stage4"] != "") {
                                       echo '<option value = "Stage4">Stage4</option>';
                                   }
                               echo '</select></td>' .
                               '<td style="border:1px solid gray;text-align:center;"><select name="' . $id . 'gender">' .
                                   '<option value ="' . $row["Gender"] . '" selected>' . $row["Gender"] . '</option>' . 
                                   '<option value = "Unspecified">Unspecified</option>' .
                                   '<option value = "Female">Female</option>' .
                                   '<option value = "Male">Male</option>' . 
                               '</select></td>' .
                               '<td style="border:1px solid gray;text-align:center;"><select name="' . $id . 'frozen">' .
                                   '<option value ="' . $row["Frozen"] . '" selected>' . $row["Frozen"] . '</option>' . 
                                   '<option value="Unspecified">Unspecified</option>' .
                                   '<option value="Yes">Yes</option>' .
                                   '<option value="No">No</option>' .
                               '</select></td>' .
                           '</tr>' .
                           '<tr>' .
                               '<td  style="border:1px solid gray;text-align:center;" colspan="3">Notes: <input type="text" name="' . $id . 'notes" value="' . $row["Notes"] .'"></td>' .
                               '<td style="border:1px solid gray;text-align:center;">' . 'Delete<br>' . '<input type="checkbox" name="delete[]" value="' . $id . '"></td>' .
                           '</tr>';
                   }
                   echo '</table><br><input name="submit" type="submit" id="submit" value="Update"></form><br><br>';
               } else {
                  echo "<br>You have no creatures in your wishlist.";
               }
           }
        } catch (mysqli_sql_exception $e) { 
            throw $e; 
        } 

        // Close the connection to the database
        $conn->close();
        [/insert_php]
      </code>
    </center>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-05 07:24:11

问题是我的服务器无法处理页面上的表单条目数量。我设置了分页,从那时起一切看起来都很好!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38689854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档