所以我创建了一个编辑个人资料页面,一切都很顺利。但后来我想使用类似的代码来更新我数据库中的另一件事。这是一个非常奇怪的错误,因为当我添加许多需要更新的值时,它拒绝工作。
<?php
session_start();
if(isset($_POST['submit'])){
$Creator = $_SESSION['username'];
$dbName = $_POST['Name'];
$dbBase_damage = $_POST['Base_damage'];
$dbDamage = $_POST['Damage'];
$dbPellets = $_POST['Pellets'];
$dbAttackspeed = $_POST['Attackspeed'];
$dbRS = $_POST['RS(first)'];
$dbRS2 = $_POST['RS(consecutive)'];
$dbLoaded = $_POST['Loaded'];
$dbReserve = $_POST['Reserve'];
$dbCritical = $_POST['Critical'];
$dbAbility = $_POST['Ability'];
$dbPiece_set = $_POST['Piece_set'];
$dbBonus_set = $_POST['Bonus_set'];
$dbDescription = $_POST['Description'];
if ($dbName && $dbBase_damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical) {
mysql_connect ("localhost", "root", "") or die ("Could not connect");
mysql_select_db("weapons") or die ("Could not connect to the database");
$wepquery = mysql_query("SELECT * FROM weapon WHERE Creator='$Creator' AND Name='$dbName'") or die ("The query could not be completed, please try again later!");
if (mysql_num_rows($wepquery) != 0) {
mysql_query ("
UPDATE weapon SET Base_Damage='$dbBase_damage', Damage='$dbDamage',
Pellets='$dbPellets', Attackspeed='$dbAttackspeed', RS(first)='$dbRS', RS(consecutive)='$dbRS2',
Loaded='$dbLoaded', Reserve='$dbReserve', Critical='$dbCritical', Ability='$dbAbility', Piece_set='$dbPiece_set',
Bonus_set='$dbBonus_set' Description='$dbDescription' WHERE Creator='$Creator' AND Name='$dbName'
") or die ("Could not update!");
echo "It just werks!";
}else echo ("That username could not be found!");
}else echo ("Something went wrong!");
}
?>
当我使用此代码时,我收到一个错误,即“Base_Damage”是未定义的索引。但是当我删除“Base_Damage”时,它根本无法更新。我仔细检查了数据库并用它创建了“武器创意”,没有任何问题。但是由于某种原因,当我减少需要更新的值的数量时,它工作得很好。如果您想知道“$Creator = $_SESSION['username'];”,我会根据谁从“nav.php”登录我的 html 代码来获取 Creator 用户名:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0" />
<title>TF2 NUT</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<div id="Container">
<div id="header">
<h1>Welcome to TF2 NUT!</h1>
</div>
<div id="nav">
<?php
include_once "nav.php";
?>
</div>
<div id="Content">
<h2>Update your submissions</h2>
<form action="edit_sub.php" method="POST">
<table>
<tr>
<td>
Choose weapon to edit:
</td>
<td>
<input type="text" name="Name" id="Name" />
</td>
</tr>
<tr>
<td>
Base damage:
</td>
<td>
<input type="text" name="Base_damage" id="Base_damage" />
</td>
</tr>
<tr>
<td>
Damage:
</td>
<td>
<input type="text" name="Damage" id="Damage" />
</td>
</tr>
<tr>
<td>
Pellets:
</td>
<td>
<input type="text" name="Pellets" id="Pellets" />
</td>
</tr>
<tr>
<td>
Attackspeed:
</td>
<td>
<input type="text" name="Attackspeed" id="Attackspeed" />
</td>
</tr>
<tr>
<td>
Reload speed:
</td>
<td>
<input type="text" name="RS(first)" id="RS(first)" />
</td>
</tr>
<tr>
<td>
Reload(consecutive):
</td>
<td>
<input type="text" name="RS(consecutive)" id="RS(consecutive)" />
</td>
</tr>
<tr>
<td>
Loaded:
</td>
<td>
<input type="text" name="Loaded" id="Loaded" />
</td>
</tr>
<tr>
<td>
Reserve:
</td>
<td>
<input type="text" name="Reserve" id="Reserve" />
</td>
</tr>
<tr>
<td>
Critical:
</td>
<td>
<input type="text" name="Critical" id="Critical" />
</td>
</tr>
<tr>
<td>
Ability:
</td>
<td>
<input type="text" name="Ability" id="Ability" />
</td>
</tr>
<tr>
<td>
Piece set:
</td>
<td>
<input type="text" name="Piece_set" id="Piece_set" />
</td>
</tr>
<tr>
<td>
Bonus set:
</td>
<td>
<input type="text" name="Bonus_set" id="Bonus_set" />
</td>
</tr>
</table>
Description:
<br />
<textarea style="resize: none;" rows="8" cols="40" id="Descripton" name="Description"></textarea>
<br />
<input type='submit' name="submit" value='Update' />
</form>
</div>
<div id="aside">
</div>
<div id="footer">
<h6>Responsible for the stuff on this site is Anton Magnusson</h6>
<h6>If I have done something wrong(I hope not ;_;) just contact me: anton_peace@hotmail.com</h6>
</div>
</div>
任何人都可以帮忙吗?:P