为什么我的链接没有将mysql行值传递给php编辑表单?

时间:2012-06-10 03:47:04

标签: php mysql forms edit

我在网页上成功显示了数据库中的信息行。我希望能够从表单中编辑该数据。出于某种原因,我对表单的链接并没有传递数据。

以下是显示数据的相关代码(包括EDIT链接):

<table cellspacing="0" cellpadding="5" border="1" width="560">
<tr style="text-align:center">
<td style="text-align:left ; width:175px">Player Name</td>
<td>Team</td>
<td>Pass Yds</td>
<td>Pass TDs</td>
<td>Int Thrown</td>
<td>Rush Yds</td>
<td>Rush TDs</td>
<td></td>
</tr>
<?php
    $result = mysql_query("SELECT ID, Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY ID;");

    while($row = mysql_fetch_array($result))
    {
    ?>

    <tr style="text-align:center">
    <td style="text-align:left"><? echo $row['Player']; ?></td>
    <td><? echo $row['Team']; ?></td>
    <td><? echo $row['Pass_Yds']; ?></td>
    <td><? echo $row['Pass_TDs']; ?></td>
    <td><? echo $row['Int_Thrown']; ?></td>
    <td><? echo $row['Rush_Yds']; ?></td>
    <td><? echo $row['Rush_TDs']; ?></td>
    <td><a href="edit.php?id=<? echo $row['ID']; ?>">Edit</a></td></tr>
<?php
    }
    ?>
</table>

这是来自edit.php的代码:

<?php
// contact to database
$connect = mysql_connect("localhost", "xxx", "xxx") or die ("Error , check your server connection.");
mysql_select_db("xxx");
$ID=$_GET['ID'];

$result = mysql_query("SELECT * FROM ff_projections WHERE ID = '$ID'") or die ("Error in query");
$row=mysql_fetch_array($result);
?>

<!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>Untitled Document</title>
</head>

<body>

<form name="edit" method="post" action="confirm.php">
<input name="ID" type="hidden" id="ID" value="<? echo $row['ID']; ?>">
<table width="560" cellspcing="0" cellpadding="5" border="0">
<tr style="text-align:center">
<td style="text-align:left ; width:175px">Player Name</td>
<td>Team</td>
<td>Pass Yds</td>
<td>Pass TDs</td>
<td>Int Thrown</td>
<td>Rush Yds</td>
<td>Rush TDs</td>
<td></td>
</tr>
<tr>
<td><? echo $row['Player']; ?></td>
<td><? echo $row['Team']; ?></td>
<td><input class="edit" name="Pass_Yds" type="text" id="Pass_Yds" value="<? echo $row['Pass_Yds']; ?>"></td>
<td><input class="edit" name="Pass_TDs" type="text" id="Pass_TDs" value="<? echo $row['Pass_TDs']; ?>"></td>
<td><input class="edit" name="Int_Thrown" type="text" id="Int_Thrown" value="<? echo $row['Int_Thrown']; ?>"></td>
<td><input class="edit" name="Rush_Yds" type="text" id="Rush_Yds" value="<? echo $row['Rush_Yds']; ?>"></td>
<td><input class="edit" name="Rush_TDs" type="text" id="Rush_TDs" value="<? echo $row['Rush_TDs']; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>

</body>
</html>

我知道很多代码已被弃用。一旦我使这个版本正常工作,我就会把注意力转移到支持代码上 - 最有可能使用mysqli API。

与此同时,对此的任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:2)

PHP区分大小写(大部分时间)。所以

$ID=$_GET['ID'];

需要

$ID=$_GET['id'];