Php 如何将数据值传递给窗体?

Php 如何将数据值传递给窗体?,php,mysql,forms,Php,Mysql,Forms,我有一个应用程序,我正在为一个幻想足球网站工作。如果你去这里: 你可以看到管理员在查看/编辑玩家时会看到什么 更新-------------------------------------- 这是a-results.php上呈现数据的相关代码,应该将数据传递到qb-edit.php上的表单: <table cellspacing="0" cellpadding="5" border="1" width="560"> <tr style="text-align:center"&

我有一个应用程序,我正在为一个幻想足球网站工作。如果你去这里:

你可以看到管理员在查看/编辑玩家时会看到什么

更新--------------------------------------

这是a-results.php上呈现数据的相关代码,应该将数据传递到qb-edit.php上的表单:

<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>Overall Pts</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT ID, Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY Pass_Yds DESC;");

while($row = mysql_fetch_array($result))
{
echo "<tr style=\"text-align:center\"><td style=\"text-align:left\">{$row['Player']}</td>";
echo "<td>{$row['Team']}</td>";
echo "<td>{$row['Pass_Yds']}</td>";
echo "<td>{$row['Pass_TDs']}</td>";
echo "<td>{$row['Int_Thrown']}</td>";
echo "<td>{$row['Rush_Yds']}</td>";
echo "<td>{$row['Rush_TDs']}</td>";
echo "<td>{$row['Overall_Pts']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td>";
echo "<td><form action=\"qb-edit.php\" method=\"post\"><input type=\"hidden\" name=\"ID\" value=\"". $row['ID'] ."\"><input type=\"submit\" name=\"submit\" value=\"Edit\"></form></td></tr>";
}
?>
</table>
<?php
$posted_id = $_POST['ID'];
?>

<!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>
<style>
body    { font-family:Arial, Helvetica, sans-serif ;
font-size:14px ;
}

.form   { width:350px ;
margin-auto ;
}

label   { clear:both ;
display:block ;
float:left ;
padding-right:8px ;
line-height:26px ;
}

input[type=text]    { float:right ;
width:163px ;
height:18px ;
margin:3px 0px ;
} 

input[type=text].short  { width:30px ;
margin-right:132px ;
}

input[type=submit]  { clear:both ;
float:left ;
margin-top:20px ;
margin-bottom:20px ;
}

select  { float:right ;
margin-right:118px ;
}
</style>
</head>

<body>

<div class="form">            
<?php 

echo $posted_id;

$result = mysql_query($connect, "SELECT * FROM ff_projections where ID='" . $posted_id . "'") or die ("Error in query");
if ($row = mysql_fetch_array($result)) {

echo "<form method='post' action='add_player.php'>";
echo "<label for='Player'>Player Name:</label> <input type='text' name='Player' value='" . $row['Player'] . "' />";
echo "<label for='Pass_Yds'>Pass Yds:</label> <input class='short' type='text' name='Pass_Yds' value='" . $row['Pass_Yds'] . "' />";
echo "<label for='Pass_TDs'>Pass TDs:</label> <input class='short' type='text' name='Pass_TDs' value='" . $row['Pass_TDs'] . "' />";
echo "<label for='Int_Thrown'>Int Thrown:</label> <input class='short' type='text' name='Int_Thrown' value='" . $row['Int_Thrown'] . "' />";
echo "<label for='Rush_Yds'>Rush Yds:</label> <input class='short' type='text' name='Rush_Yds' value='" . $row['Rush_Yds'] . "' />";
echo "<label for='Rush_TDs'>Rush TDs:</label> <input class='short' type='text' name='Rush_TDs' value='" . $row['Rush_TDs'] . "' />";
echo "<label for='Overall_Pts'>Overall Pts:</label> <input class='short' type='text' name='Overall_Pts' value='" . $row['Overall_Pts'] . "' />";
echo "<input type='submit' name='submit' value='Update Player' />";
echo "<input type='hidden' name='id' value='" . $row['ID'] . "' />";
echo "</form>";
}
?>
</div>


</body>
</html>
$result = mysql_query($connect, "SELECT * FROM ff_projections where ID='" . $posted_id . "'") or die ("Error in query");
这是qb-edit.php的第55行:

<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>Overall Pts</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT ID, Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY Pass_Yds DESC;");

while($row = mysql_fetch_array($result))
{
echo "<tr style=\"text-align:center\"><td style=\"text-align:left\">{$row['Player']}</td>";
echo "<td>{$row['Team']}</td>";
echo "<td>{$row['Pass_Yds']}</td>";
echo "<td>{$row['Pass_TDs']}</td>";
echo "<td>{$row['Int_Thrown']}</td>";
echo "<td>{$row['Rush_Yds']}</td>";
echo "<td>{$row['Rush_TDs']}</td>";
echo "<td>{$row['Overall_Pts']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td>";
echo "<td><form action=\"qb-edit.php\" method=\"post\"><input type=\"hidden\" name=\"ID\" value=\"". $row['ID'] ."\"><input type=\"submit\" name=\"submit\" value=\"Edit\"></form></td></tr>";
}
?>
</table>
<?php
$posted_id = $_POST['ID'];
?>

<!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>
<style>
body    { font-family:Arial, Helvetica, sans-serif ;
font-size:14px ;
}

.form   { width:350px ;
margin-auto ;
}

label   { clear:both ;
display:block ;
float:left ;
padding-right:8px ;
line-height:26px ;
}

input[type=text]    { float:right ;
width:163px ;
height:18px ;
margin:3px 0px ;
} 

input[type=text].short  { width:30px ;
margin-right:132px ;
}

input[type=submit]  { clear:both ;
float:left ;
margin-top:20px ;
margin-bottom:20px ;
}

select  { float:right ;
margin-right:118px ;
}
</style>
</head>

<body>

<div class="form">            
<?php 

echo $posted_id;

$result = mysql_query($connect, "SELECT * FROM ff_projections where ID='" . $posted_id . "'") or die ("Error in query");
if ($row = mysql_fetch_array($result)) {

echo "<form method='post' action='add_player.php'>";
echo "<label for='Player'>Player Name:</label> <input type='text' name='Player' value='" . $row['Player'] . "' />";
echo "<label for='Pass_Yds'>Pass Yds:</label> <input class='short' type='text' name='Pass_Yds' value='" . $row['Pass_Yds'] . "' />";
echo "<label for='Pass_TDs'>Pass TDs:</label> <input class='short' type='text' name='Pass_TDs' value='" . $row['Pass_TDs'] . "' />";
echo "<label for='Int_Thrown'>Int Thrown:</label> <input class='short' type='text' name='Int_Thrown' value='" . $row['Int_Thrown'] . "' />";
echo "<label for='Rush_Yds'>Rush Yds:</label> <input class='short' type='text' name='Rush_Yds' value='" . $row['Rush_Yds'] . "' />";
echo "<label for='Rush_TDs'>Rush TDs:</label> <input class='short' type='text' name='Rush_TDs' value='" . $row['Rush_TDs'] . "' />";
echo "<label for='Overall_Pts'>Overall Pts:</label> <input class='short' type='text' name='Overall_Pts' value='" . $row['Overall_Pts'] . "' />";
echo "<input type='submit' name='submit' value='Update Player' />";
echo "<input type='hidden' name='id' value='" . $row['ID'] . "' />";
echo "</form>";
}
?>
</div>


</body>
</html>
$result = mysql_query($connect, "SELECT * FROM ff_projections where ID='" . $posted_id . "'") or die ("Error in query");

我正在疯狂地尝试让它工作…

只需将其数据库记录的ID作为参数传递,可能作为隐藏字段,然后在下一页使用它从数据库中提取其记录。

只需将其数据库记录的ID作为参数传递,可能作为隐藏字段,然后使用它在下一页从数据库中提取他们的记录。

这个想法是你传递玩家的ID(可以是GET或POST方法),我认为最好的方法是POST,因为你可以将ID传递到URL中

例如:

player_id=1 Vince Young如果您创建指向此页面的链接,它将显示编辑页面

player_id=2 Ryan Tannehill如果创建指向此页面的链接,它将显示编辑页面

等等

当然,你必须考虑一些事情:

  • 您必须创建一个名为edit_player的php文件及其函数
  • 如果您不检查是否有人可以打开浏览器副本并粘贴如下链接,则必须验证会话['user']是否具有编辑播放机的权限:http://digitaldemo.net/kickass/edit_player.php?id=1 并且可以编辑你的帖子
  • 如果我使用某种md5算法来发送用户ID,那么我将限制入侵者
  • 请参阅本安全指南,它将帮助您保护您的网站:


    我们的想法是传递玩家的ID(可以是GET或POST方法),我认为最好的方法是POST,因为您可以将ID传递到URL中

    例如:

    player_id=1 Vince Young如果您创建指向此页面的链接,它将显示编辑页面

    player_id=2 Ryan Tannehill如果创建指向此页面的链接,它将显示编辑页面

    等等

    当然,你必须考虑一些事情:

  • 您必须创建一个名为edit_player的php文件及其函数
  • 如果您不检查是否有人可以打开浏览器副本并粘贴如下链接,则必须验证会话['user']是否具有编辑播放机的权限:http://digitaldemo.net/kickass/edit_player.php?id=1 并且可以编辑你的帖子
  • 如果我使用某种md5算法来发送用户ID,那么我将限制入侵者
  • 请参阅本安全指南,它将帮助您保护您的网站:


    我相信你的错误是由这里造成的

    “从ID=”的ff_投影中选择*”$贴上你的身份证。“'”

    在选择好的前,您已经开始了双引号 但是,当您达到ID=时,您结束了这组引号 删除双引号

    换句话说

    "SELECT * FROM ff_projections WHERE ID = '$posted_id'"
    
    而不是

     "SELECT * FROM ff_projections where ID='" . $posted_id . "'"
    

    我相信你的错误是在这里造成的

    “从ID=”的ff_投影中选择*”$贴上你的身份证。“'”

    在选择好的前,您已经开始了双引号 但是,当您达到ID=时,您结束了这组引号 删除双引号

    换句话说

    "SELECT * FROM ff_projections WHERE ID = '$posted_id'"
    
    而不是

     "SELECT * FROM ff_projections where ID='" . $posted_id . "'"
    

    在包含这些按钮的每个表单中,输入与每个播放器相关联的记录的ID号。然后,您可以在qb-edit.php页面上以
    $\u POST
    变量的形式获取ID,并使用它从您的数据库中获取他们的信息。因此,编辑按钮表单代码如下所示:?在组成这些按钮的每个表单中,输入与每个播放器关联的记录的ID号。然后,您可以在qb-edit.php页面上以
    $\u POST
    变量的形式获取该ID,并使用它从您的数据库中获取他们的信息。那么,编辑按钮表单代码是否如下所示:?唉……我犯了一个愚蠢的错误。我从未将qb-edit.php连接到stupd db。啊!必须得到。斯里eep。。。谢谢你的帮助!唉……我犯了个愚蠢的错误。我从未将qb-edit.php连接到stupd db。啊!必须得到。斯里eep。。。谢谢你的帮助!