gpt4 book ai didi

php - HTML 表单在输入一定数量后不更新信息

转载 作者:行者123 更新时间:2023-11-29 20:39:00 25 4
gpt4 key购买 nike

下面包含页面上的所有 PHP 脚本。该页面表现出色,直到我的一位用户遇到问题。他们给我发消息说编辑功能不再起作用。通常,当您单击“更新”时,您会看到一条消息,说明您的愿望 list 已更新,但对于该用户来说,当他们单击更新按钮时,它只会刷新页面。它不再更改数据库中的信息。

我尝试从数据库本身中删除一些条目,然后用户就可以进行编辑。一旦他们将生物添加回来,但它不再起作用,事实上它在不同的位置损坏了。

心愿单更新功能第一次破坏了大约 162 个生物,这次破坏了大约 168 个生物。

什么可能导致这个奇怪的故障?我能做什么来修复它?谢谢!

   <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>

最佳答案

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

关于php - HTML 表单在输入一定数量后不更新信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38689854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com