0

I have an edit button at the end of a table of mysql records that displays in a webpage.

When I click the edit button, however, my edit.php just generates a blank page.

I can't figure out why:

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

I have ID as a hidden field because I don't want it visible or editable.

Here is the page that uses 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>
royhowie
  • 11,075
  • 14
  • 50
  • 67
Cynthia
  • 5,273
  • 13
  • 42
  • 71
  • 4
    You should remove your passwords from above post. Then enable error_reporting, and look into your webservers error.log when you get a blank page. – mario Jun 05 '12 at 01:45
  • possible duplicate of [PHP production server - turn on error messages](http://stackoverflow.com/questions/1824282/php-production-server-turn-on-error-messages) –  Jun 05 '12 at 01:58
  • Also verify that the query actually returns some data. And why generate all that HTML through echo statements? Easier to maintain if you just drop a little PHP into the HTML instead. – Marvo Jun 05 '12 at 02:00
  • After turning on error reporting, I get: Notice: Undefined index: ID in /home/kaffcom/public_html/projections/qb-edit.php on line 12 – Cynthia Jun 05 '12 at 02:02
  • And line 12 is $posted_id = $_POST['ID']; – Cynthia Jun 05 '12 at 02:02
  • Are you sure that the method in your form on the previous page is set to POST and not GET (or left off entirely)? – King Skippus Jun 05 '12 at 02:09
  • Yes it is set to post. Here is that line of code: echo "
    ";
    – Cynthia Jun 05 '12 at 02:27

1 Answers1

0

Never forget to properly sanitize any entry touching your database "mysql_real_escape_string();.

But it seems that its its complaining about the undefined index $_POST['ID'];, its because either nothing is being sent to it or perhaps there is a naming issue being posted to that page.

Try to set a static variable of one of your values as $posted_id: $posted_id = 3262732 (or a known post id) to see if your form correctly returns.

If that does work then review what data is being posted to edit.php.

  • I edited my original question to include the code from the file that is posting to edit.php... – Cynthia Jun 05 '12 at 02:26
  • So unless i'm missing something, this part: `echo "
    ";` Does not have any elements to the form that its passing to edit.php except for Submit, try setting a form element that represents the data you want to modify/update, ``
    – Krazybean Jun 05 '12 at 02:38