Update Form not submitting

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:
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);
?>
And the page itself:
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);
?>
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.
 
Last edited:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
last line of your query
Code:
WHERE ID = ".$iID;
try
Code:
WHERE ID = '".$iID."'";
 
Last edited:

xmakina

New Member
Messages
264
Reaction score
0
Points
0
Interesting. Add to your error reporting the $query variable. Take that output and run it in the phpMyAdmin SQL area, it'll provide you with a more descriptive error and you can also edit the query faster.
 

mephis

New Member
Messages
39
Reaction score
0
Points
0
It might also be a good idea to dump your $_POST vars, since you say:
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 (...)

You might be generating some malformed HTML there which is screwing up your _POST, and in turn screwing up the query
 

ChiBuki

New Member
Messages
11
Reaction score
0
Points
0
Okay it didn't seem to report back an error with error_reporting(E_ALL). Now I decided to throw the dropdown menu altogether for debugging test and use simple input text for the rank, yet the form is still not submitting. :happysad:

HTML:
<label for="rank">Character Rank:</label> 
        <input type="text" name="rank" id="rank" maxlength="3" value="<?php echo $row["Rank"];?>" />

When I click the submit button, the value changes back to teh database value.

_______________________
Update
I found the syntax error. I missed commas at the php and now the form submits.

PHP:
FourPoints ='".$sFourPoints."'
            ThreePoints ='".$sThreePoints."'
            TwoPoints ='".$sTwoPoints."'
            OnePoints ='".$sOnePoints."'
            DateUpdated ='".$sDateUpdated."'

However, new problem arose. I tried using the dropdown menu again, and whenever I click inside the <select></select> tag, Dreamweaver crashed every single time. That scared me but it seems to be OK with regular text form.
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Dreamweaver crashed every single time.

Don't you just love DW!!!

Its fine when you only use the pre-set functions but as soon as you put in anything different, DW stops working for an "unspecified" reason.

This might make you think you've screwed your code up, or worse... Dreamweaver - but its OK - Its just DW playing games with your mind!!!

I have multiple crash errors now with my site although the code is fine and works great..

I might be going back to notepad!:nuts:
 
Top