我对 PHP 比较陌生,在一个不相关的领域工作了几年后,我回到了学校。我正在为我爸爸做一个外部项目,并且遇到了表面上看起来很容易解决但我似乎无法解决的问题。
在有问题的页面上,它显示了一个联赛中的球员名单和他们的得分。它下面的表格有一个文本框,允许您输入名称和三个按钮;第一个添加名称作为玩家(默认得分为 0),从玩家列表中删除该玩家,第三个用于调整该玩家的分数。我让前两个(“添加”和“删除”)按我的意愿工作,但是我遇到的问题是分数调整一个。
如果您单击“调整分数”按钮,它会显示一个新的文本框以输入分数以及另一个按钮以实际提交分数。问题是当您按下新按钮来调整分数时没有任何反应,此时我刚刚得到了一个测试“回声”语句,应该在提交时显示,但这并没有发生。下面是有问题的代码。关于如何解决的任何想法?感谢您的任何建议。
<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>