无法更新SQL数据库
So I created an edit profile page and everything went fine. But later on I wanted to use similar code to update another thing inside my database. Its a very odd bugg because when I add to many values that need to be update it refuse to work.
<?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!");
}
?>
When I use this code I get an error that 'Base_Damage' is undefined index. But when I remove 'Base_Damage', it can not update at all. I have double checked the database and created 'weapon ideas' with it without problems. But for some reason when I reduce the amount of values that need to be update it works just fine. If you wonder about the "$Creator = $_SESSION['username'];", I get the Creator username depending on who is logged in from "nav.php" My html code:
<!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>
Anyone can help? :P
i guess your if statment is not readable and thats why you couldnt update
- first your name
name="Base_damage"
ia not same as your variable index$dbBase_Damage = $_POST['Base_Damage'];
it should be
$dbBase_Damage = $_POST['Base_damage']; // with small d
try replave this also
if ($dbName && $dbBase_Damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical)
edit:
in your query replace this
RS(first)='$dbRS', RS(consecutive)='$dbRS2'
by
`RS(first)`='$dbRS', `RS(consecutive)`='$dbRS2'
EDIT2:
please replace
or die ("Could not update!");
with
or die(mysql_error()); // like that you can see what error or what goes wrong.
EDIT3.
Bonus_set='$dbBonus_set' , Description=
^^//you missed coma here