I’m relatively new to PHP, I’m back in school after working in an unrelated field for a number of years. I’m working on an outside project for my Dad and have run into what appears on the surface to be an easy-to-solve issue that I can’t seem to resolve.
On the page in question it displays a list of players in a league and their score. The form below it has a text box allowing you to enter a name and three buttons; one to add the name as a player (with a default score of 0), delete that player from the list of players, and a third to adjust the score for that player. I got the first two (“add” and “delete”) to work as I’d like, however where I’m running into a problem is with the score adjustment one.
If you click the “adjust score” button it displays a new text box to enter the score along with another button to actually submit it. The problem is nothing happens when you press the new button to adjust the score, at this point I’ve just got a test “echo” statement in there that should be displaying on submission, but that’s not happening. Below is the code in question. Any thoughts on how I can fix? Thanks for any suggestions.
<html>
<head>
<LINK REL="stylesheet" type="text/css" href="styles/footballTest.css" />
<title>VFW Football testing</title>
</head>
<body>
<?php
$dbConnect = mysql_connect("localhost", "root","");
$dbName = "vfwleaguetest";
$getPlayers = "SELECT * FROM `players`";
if(!$dbConnect)
{
echo "<p>Connection failed</p>";
}
if(mysql_select_db($dbName, $dbConnect) === false)
{
echo "<p>Could not select the database ".$dbName ."<br/>".mysql_error($dbConnect)." </p>";
}
if(isset($_POST['submit']))
{
$name=@$_POST['nameAdd'];
$playerAdd = "INSERT INTO `vfwleaguetest`.`players` (`playerName`, `seasonTotal`) VALUES ('".$name."', '0')";
if(mysql_query($playerAdd, $dbConnect) === false)
{
echo "<p>Error adding player to database: ".mysql_error($dbConnect)."</p>";
}
}
unset($_POST['submit']);
if(isset($_POST['delete']))
{
$name= @$_POST['nameAdd'];
$playerDelete = "DELETE FROM `vfwleaguetest`.`players` WHERE `players`.`playerName` = '".$name."'";
if(mysql_query($playerDelete, $dbConnect) ===false)
{
echo "<p>Error deleting player to database: ".mysql_error($dbConnect)."</p>";
}
else
{
echo $name." successfully removed from player list";
}
}
if(isset($_POST['adjust']))
{
?>
<br/>
<input type='text' name='scoreAdjust' size=5 />
<input type='submit' name='fixScore' value='new season total for <?php echo $_POST['nameAdd'];?>' />
<?php
if(isset($_POST['fixScore'])) //THIS IS WHERE THE PROBLEM SEEMS TO LIE
{
echo "after fixScore click";
//add sql below
}
}
?>
<form name="players" action="" method="post">
<?php
$playerList = mysql_query($getPlayers, $dbConnect);
echo "<table><th><tr>";
echo "<td>Player name</td><td>Season total</td></tr></th>";
while(($row = mysql_fetch_row($playerList)) != false)
{
echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";
}
echo "</table>";
?>
Manage players <input type="text" name="nameAdd" />
<input type="submit" name="submit" value="add" />
<input type="submit" name="delete" value="delete" />
<input type="submit" name="adjust" value="adjust score" />
</form>
</body>
</html>
the problem is score adjust inputs are out of the form:
you need: