下面是页面上的所有PHP脚本。该页面可以创建奇迹,直到我的一个用户遇到问题。他们给我发了消息,并说编辑功能不再起作用。通常,当您点击“更新”时您将看到一条消息,表明您的愿望清单已更新,但对于此用户,当他们点击更新按钮时,它只是刷新了页面。它不再更改数据库中的信息。
我尝试从数据库中删除一些条目,然后用户就可以编辑了。一旦他们将这些生物添加回来,但它不再起作用,事实上它在另一个地方爆发了。
第一次愿望清单更新功能突破了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>
答案 0 :(得分:0)
问题是我的服务器无法处理页面上的表单条目数。我设置了分页,从那时起一切都很好!