English 中文(简体)
我如何将数据值传送到表单?
原标题:How do I pass data values to a form?

我有一个申请 我为一个幻想足球场工作。

http://digitaldemo.net/kickass/a-results.php" rel=“nofollow'>http://digitaldemo.net/kickass/a-resources.php

您可以看到当管理员去查看/编辑玩家时会看到什么。

更新 - - - - - - - - -

这是关于结果.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>

这是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");

我快疯了,想把事情办成...

最佳回答

只需将数据库记录的身份标识作为参数, 可能是一个隐藏字段, 然后用它从下一页的数据库中调出他们的记录 。

问题回答

想法是您通过玩家的 ID (可以是 Get 或 POST 方法), 我认为最好的方法是 POST, 因为您可以将 ID 传送到 URL

例如:

player_id=1 Vince Young ,如果您创建链接到此页面 http://digitaldemo.net/kickass/edit_player.php?id=2 它将会显示编辑页面

等等等

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

  1. You have to create a php file called edit_player and the functions on it.
  2. You have to validate the SESSION[ user ] has the permission to edit a player, if you don t check that someone can open a browser copy and paste a link like this :http://digitaldemo.net/kickass/edit_player.php?id=1 and will able to edit your post.
  3. If I ll use some kind of md5 algorithm to send the user ID, doing that I will restrict the intruder.

请看这份安全指南, 它会帮助您保护您的网站:

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

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

" 编号=. 美元贴上. " 。 "

you started your double quotes before SELECT which is good however when you got to ID= you ended that set of quotes Remove the double quotes

换句话说,

"SELECT * FROM ff_projections WHERE ID =  $posted_id "

代替

 " 编号=. 美元贴上. " 。 "




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签