为什么我的PHP代码编辑我的mySQL表显示为空白页?

时间:2012-06-05 01:41:00

标签: php mysql

我在显示的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>

1 个答案:

答案 0 :(得分:0)

永远不要忘记正确清理触及数据库的任何条目“mysql_real_escape_string();.

但它似乎是抱怨未定义的索引$ _POST ['ID'];,因为要么没有发送任何内容,要么就是有一个命名问题被发布到该页面。

尝试将其中一个值的静态变量设置为$ posted_id: $ posted_id = 3262732(或已知的帖子ID),以查看您的表单是否正确返回。

如果确实有效,那么请查看要发布到edit.php。

的数据