2012-05-24 60 views
0

我有一個應用程序,我正在爲幻想足球網站工作。如果你去這裏:如何將數據值傳遞給表單?

http://digitaldemo.net/kickass/a-results.php

你可以看到管理員會看到,當他們去查看/編輯播放器。

UPDATE --------------------------------------

這是

<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> 

,這是QB-edit.php的內容:在-results.php呈現到上QB-edit.php形式的數據和應該通數據相關的代碼

<?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> 

我收到一條錯誤消息:

PHP Warning: mysql_query() expects parameter 2 to be resource, string given in C:\\xampp\\htdocs\\kickass\\qb-edit.php on line 55, referer: http://localhost/kickass/a-results.php 

這是QB-edit.php的第55行:

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

我去堅果試圖讓這個工作...

回答

1

只需通過ID爲自己的數據庫記錄作爲參數,可能是一個隱藏字段,然後用它從下一頁的數據庫中提取記錄。

+0

你有點迷失了我。我對編程極其新穎...... – Cynthia

+0

在包含這些按鈕的每種表單中,都放置了與每個玩家關聯的記錄的ID號。然後,您可以在qb-edit.php頁面上將該ID作爲'$ _POST'變量獲取,並使用它從數據庫獲取其信息。 –

+0

那麼編輯按鈕表單代碼看起來就像這樣:

< input type =「submit」name =「submit」value =「Edit」>
? – Cynthia

1

的想法是,你通過玩家的ID(可以是如GET或POST方法),我認爲最好的方法是POST,因爲你可以通過ID到URL

爲例如:

player_id = 1 Vince年輕人如果您創建一個鏈接到http://digitaldemo.net/kickass/edit_player.php?id=1這個頁面會顯示在編輯頁面

player_id = 2瑞安坦尼希爾,如果你創建一個鏈接到http://digitaldemo.net/kickass/edit_player.php?id=2它將此頁面迪張開編輯頁面

等等等等

當然你得體諒一些東西的

  1. 你必須創建一個PHP文件名爲edit_player和它的職能。
  2. 如果您不檢查某人是否可以打開瀏覽器副本並粘貼如下鏈接,則必須驗證SESSION ['user']是否有權編輯播放器:http://digitaldemo.net/ kickass/edit_player.php?id = 1並且能夠編輯你的文章。
  3. 如果我將使用某種md5算法來發送用戶ID,那麼我會限制入侵者。

請看看這個安全指南,它會幫助您保護您的網站:

http://phpsec.org/projects/guide/

1

你的錯誤都在這裏引起我相信

「SELECT * FROM ff_projections其中ID ='「。 $ posting_id。 「'」

您選擇哪個好之前就開始你的雙引號 然而,當你練到ID =你結束了一套報價 的刪除雙引號

所以換句話說

"SELECT * FROM ff_projections WHERE ID = '$posted_id'" 

而不是

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

我試着改變它,仍然沒有快樂...... – Cynthia

+0

感嘆......我的愚蠢的錯誤。我從來沒有將qb-edit.php連接到stupd數據庫。哎呀!必須。得到。睡吧...謝謝你的幫助! – Cynthia