我在一個mysql記錄表的末尾有一個編輯按鈕,它在網頁中顯示 。爲什麼我的php代碼編輯mySQL表格顯示爲空白頁面?
然而,當我點擊編輯按鈕時,我的edit.php只是生成一個空白頁面。
我想不通爲什麼:
<?php
// contact to database
$connect = mysql_connect("localhost", "xxx", "xxx") or die ("Error , check your server connection.");
mysql_select_db("xxx");
?>
<?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>
</head>
<body>
<div class="form">
<?php
$result = mysql_query("SELECT * FROM ff_projections WHERE ID = '$posted_id'") or die ("Error in query");
if ($row = mysql_fetch_array($result)) {
echo "<form method='post' action='update.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 "<input type='submit' name='submit' value='Update Player' />";
echo "<input type='hidden' name='ID' value='" . $row['ID'] . "' />";
echo "</form>";
}
?>
</div>
</body>
</html>
我有ID作爲隱藏字段,因爲我不希望它可見或編輯。
下面是一個使用edit.php頁:
<?php
// contact to database
$connect = mysql_connect("localhost", "xxx", "xxx") or die ("Error , check your server connection.");
mysql_select_db("xxx");
?>
<!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>Kick Ass Fantasy Football Projections</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".tab_content").hide();
$(".tab_content:first").show();
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tab_content").hide();
var activeTab = $(this).attr("rel");
$("#"+activeTab).fadeIn();
});
});
</script>
</head>
<body>
<div>
<FORM METHOD="LINK" ACTION="index.php" style="margin:10px 0px">
<INPUT TYPE="submit" VALUE="Add More Players" style="padding:6px">
</FORM>
</div>
<ul class="tabs">
<li class="active" rel="tab1"> QB</li>
<li rel="tab2"> RB</li>
<li rel="tab3"> WR</li>
<li rel="tab4"> TE</li>
<li rel="tab5"> K</li>
<li rel="tab6"> Def/ST</li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content">
<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>TFP</td>
<td>Edit Player</td>
</tr>
<?php
$result = mysql_query("SELECT Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Total_Fantasy_Pts, ID 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['Total_Fantasy_Pts']}</td>";
echo "<td>{$row['ID']}</td>";
echo "<td><form action=\"edit.php\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Edit\"></form></td></tr>";
}
?>
</table>
</div>
</div>
<div class="tab_container">
<div id="tab2" class="tab_content">
<table cellspacing="0" cellpadding="5" border="1" width="560">
<tr style="text-align:center">
<td style="width:175px ; text-align:left">Player Name</td>
<td>Team</td>
<td>Rush Yds</td>
<td>Rush TDs</td>
<td>Rec Yds</td>
<td>Rec TDs</td>
<td>Rec</td>
<td>Fumbles</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT Player, Team, Rush_Yds, Rush_TDs, Rec_Yds, Rec_TDs, Receptions, Fumbles, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'RB' ORDER BY Rush_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['Rush_Yds']}</td>";
echo "<td>{$row['Rush_TDs']}</td>";
echo "<td>{$row['Rec_Yds']}</td>";
echo "<td>{$row['Rec_TDs']}</td>";
echo "<td>{$row['Receptions']}</td>";
echo "<td>{$row['Fumbles']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td></tr>";
}
?>
</table>
</div>
</div>
<div class="tab_container">
<div id="tab3" class="tab_content">
<table cellspacing="0" cellpadding="5" border="1" width="560">
<tr style="text-align:center">
<td style="width:175px ; text-align:left">Player Name</td>
<td>Team</td>
<td>Rec Yds</td>
<td>Rec TDs</td>
<td>Rec</td>
<td>Fumbles</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT Player, Team, Rec_Yds, Rec_TDs, Receptions, Fumbles, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'WR' ORDER BY Rec_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['Rec_Yds']}</td>";
echo "<td>{$row['Rec_TDs']}</td>";
echo "<td>{$row['Receptions']}</td>";
echo "<td>{$row['Fumbles']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td></tr>";
}
?>
</table>
</div>
</div>
<div class="tab_container">
<div id="tab4" class="tab_content">
<table cellspacing="0" cellpadding="5" border="1" width="560">
<tr style="text-align:center">
<td style="width:175px ; text-align:left">Player Name</td>
<td>Team</td>
<td>Rec Yds</td>
<td>Rec TDs</td>
<td>Rec</td>
<td>Fumbles</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT Player, Team, Rec_Yds, Rec_TDs, Receptions, Fumbles, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'TE' ORDER BY Rec_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['Rec_Yds']}</td>";
echo "<td>{$row['Rec_TDs']}</td>";
echo "<td>{$row['Receptions']}</td>";
echo "<td>{$row['Fumbles']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td></tr>";
}
?>
</table>
</div>
</div>
<div class="tab_container">
<div id="tab5" class="tab_content">
<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>FG</td>
<td>Extra Pts</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT Player, Team, FG, Extra_Pts, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'K' ORDER BY FG 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['FG']}</td>";
echo "<td>{$row['Extra_Pts']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td></tr>";
}
?>
</table>
</div>
</div>
<div class="tab_container">
<div id="tab6" class="tab_content">
<table cellspacing="0" cellpadding="5" border="1" width="560">
<tr style="text-align:center">
<td>Team</td>
<td>Sacks</td>
<td>Int</td>
<td>Def TD</td>
<td>ST TD</td>
<td>Shutouts</td>
<td>TFP</td>
</tr>
<?php
$result = mysql_query("SELECT Team, Sacks, Int_Caught, Def_TD, ST_TD, Shutouts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'Def/ST' ORDER BY Def_TD DESC;");
while($row = mysql_fetch_array($result))
{
echo "<tr style=\"text-align:center\"><td>{$row['Team']}</td>";
echo "<td>{$row['Sacks']}</td>";
echo "<td>{$row['Int_Caught']}</td>";
echo "<td>{$row['Def_TD']}</td>";
echo "<td>{$row['ST_TD']}</td>";
echo "<td>{$row['Shutouts']}</td>";
echo "<td>{$row['Total_Fantasy_Pts']}</td></tr>";
}
?>
</table>
</div>
</div>
</body>
</html>
你應該從上面的帖子中刪除你的密碼。然後啓用error_reporting,並在您獲得空白頁面時查看您的webservers error.log。 – mario
[PHP生產服務器 - 打開錯誤消息]的可能重複(http://stackoverflow.com/questions/1824282/php-production-server-turn-on-error-messages) – 2012-06-05 01:58:16
也驗證查詢實際返回一些數據。爲什麼通過echo語句生成所有的HTML?更容易維護,如果你只是將一些PHP放入HTML中。 – Marvo