ChiBuki
New Member
- Messages
- 11
- Reaction score
- 0
- Points
- 0
Hi,
For my character data table, I'm making an update form in a page for users to update. It appears when I submit the info, it didn't change anything in my mysql database. I went over this several times but couldn't find the cause and it's probably something minor...
This is the php before body:
And the page itself:
Additionally, where it says "Character Rank:" I think something's wrong with the code. It should display the character's rank by default, but instead it always display the first option in the dropdown menu. In addition to my not-submitting form, can someone please point out the right way to echo dropdown menu using PHP?
Thanks.
For my character data table, I'm making an update form in a page for users to update. It appears when I submit the info, it didn't change anything in my mysql database. I went over this several times but couldn't find the cause and it's probably something minor...
This is the php before body:
PHP:
<?php
include("connect.php");
if(isset($_POST["action"]))
{
$sFeaturedCharacter = $_POST["featuredcharacter"];
$sRank = $_POST["rank"];
$sAverage = $_POST["average"];
$sPointsEarned = $_POST["pointsearned"];
$sTotalVotes = $_POST["totalvotes"];
$sFivePoints = $_POST["fivepoints"];
$sFourPoints = $_POST["fourpoints"];
$sThreePoints = $_POST["threepoints"];
$sTwoPoints = $_POST["twopoints"];
$sOnePoints = $_POST["onepoints"];
$sDateUpdated = $_POST["dateupdated"];
$iID = $_POST['which'];
$query = "UPDATE CharacterData SET
FeaturedCharacter ='".$sFeaturedCharacter."',
Rank ='".$sRank."',
Average ='".$sAverage."',
PointsEarned ='".$sPointsEarned."',
TotalVotes ='".$sTotalVotes."',
FivePoints ='".$sFivePoints."',
FourPoints ='".$sFourPoints."'
ThreePoints ='".$sThreePoints."'
TwoPoints ='".$sTwoPoints."'
OnePoints ='".$sOnePoints."'
DateUpdated ='".$sDateUpdated."'
WHERE ID = ".$iID;
//Run query
$result = mysql_query($query);
if(!result)
{
echo $query;
die("Could not query the databse:<br />". mysql_error());
}
}
if(!isset($iID))
{
$iID = $_GET["id"];
}
$query = "SELECT * FROM CharacterData WHERE ID = $iID";
//Run query
$result = mysql_query($query);
if(!$result)
{
die("Could not query the database:<br />". mysql_error());
}
$row = mysql_fetch_assoc($result);
?>
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update A Character</title>
<script type="text/javascript" src="ton.js"></script>
<link href="ton.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<h1>Update A Character</h1>
<h3>Updating data for <?php echo $row["FeaturedCharacter"];?></h3>
<form id="editcharacter" name="editcharacter" method="post" action="edittest.php">
<label for="rank">Character Rank:</label>
<select name="rank" id="rank">
<option value="A+" <?php if ($sRank == "A+") { echo("selected='selected'"); }; ?>>A+</option>
<option value="A" <?php if ($sRank == "A") { echo("selected='selected'"); }; ?>>A</option>
<option value="A-" <?php if ($sRank == "A-") { echo("selected='selected'"); }; ?>>A-</option>
<option value="B-" <?php if ($sRank == "B+") { echo("selected='selected'"); }; ?>>B+</option>
<option value="B" <?php if ($sRank == "B") { echo("selected='selected'"); }; ?>>B</option>
<option value="B-" <?php if ($sRank == "B-") { echo("selected='selected'"); }; ?>>B-</option>
<option value="C+" <?php if ($sRank == "C+") { echo("selected='selected'"); }; ?>>C+</option>
<option value="C" <?php if ($sRank == "C") { echo("selected='selected'"); }; ?>>C</option>
<option value="C-" <?php if ($sRank == "C-") { echo("selected='selected'"); }; ?>>C-</option>
<option value="D+" <?php if ($sRank == "D+") { echo("selected='selected'"); }; ?>>D+</option>
<option value="D" <?php if ($sRank == "D") { echo("selected='selected'"); }; ?>>D</option>
<option value="F" <?php if ($sRank == "F") { echo("selected='selected'"); }; ?>>F</option>
</select>
<br />
<label for="average">Average:</label>
<input type="text" name="average" id="average" maxlength="4" value="<?php echo $row["Average"];?>" />
<br />
<label for="pointsearned">Total Points Earned:</label>
<input type="text" name="pointsearned" id="pointsearned" maxlength="4" value="<?php echo $row["PointsEarned"];?>" />
<br />
<label for="totalvotes">Total Votes:</label>
<input type="text" name="totalvotes" id="totalvotes" maxlength="4" value="<?php echo $row["TotalVotes"];?>" />
<br />
<label for="fivepoints">5 pts:</label>
<input type="text" name="fivepoints" id="fivepoints" maxlength="3" value="<?php echo $row["FivePoints"];?>" />
<br />
<label for="fourpoints">4 pts:</label>
<input type="text" name="fourpoints" id="fourpoints" maxlength="3" value="<?php echo $row["FourPoints"];?>" />
<br />
<label for="threepoints">3 pts:</label>
<input type="text" name="threepoints" id="threepoints" maxlength="3" value="<?php echo $row["ThreePoints"];?>" />
<br />
<label for="twopoints">2 pts:</label>
<input type="text" name="twopoints" id="twopoints" maxlength="3" value="<?php echo $row["TwoPoints"];?>" />
<br />
<label for="onepoints">1 pts:</label>
<input type="text" name="onepoints" id="onepoints" maxlength="3" value="<?php echo $row["OnePoints"];?>" />
<br /><br />
<input type="hidden" name="dateupdated" id="dateupdated" value="<?php echo date('Y-m-d');?>" />
<input type="hidden" name="which" value="<?php echo $row["ID"];?>" />
<input type="hidden" name="action" id="action" value="edit" />
<input type="submit" name="Submit" value="Update this Character" />
<?php
if(isset($_POST["action"]))
{
?>
<p style="color:red">Changes Saved.</p>
<?php } ?>
</form>
<p><a href="http://forums.x10hosting.com/programming-help/characterlist.php">Back to Main Page</a></p>
</div>
</body>
</html>
<?php
mysql_close($connection);
?>
Thanks.
Last edited: