Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Help writing points field to table, Please help

    I am really looking for help here. I know I'm a newby but I don't know where to turn. I can't get points from the html input to write to the table.

    the table is for an office pool of weekly nfl picks, based on PHPPick'em.

    The table picks has the structure of userid, gameid, pickid and points (integer default = 1). There is one row for each user for each game. I want to implement instead of points being 1 for each game, the user selects 1 through 15 (or however many games there are that week). I am having trouble getting this form to pass points to the table and also need to find something to validate it.


    This file displays the ones (default value) perfectly after picks are made, but it doesn't pass the points from the html input to the table.


    I am very new to PHP, and usually am able to modify others code to adapt to my needs, but I am really stuck on this one, any help would be greatly appreciated.


    I tried multiple ways putting it into the Insert statement, and this last one I tried putting it into an update statement after the insert, not having any luck.



    PHP Code:
    <?php
    require_once('includes/application_top.php');
    require(
    'includes/classes/team.php');

    if (
    $_POST['action'] == 'Submit') {
        
    $week $_POST['week'];
        
    $cutoffDateTime getCutoffDateTime($week);
        
        
    //update summary table
        
    $sql "delete from " $db_prefix "picksummary where weekNum = " $_POST['week'] . " and userID = " $user->userID ";";
        
    mysql_query($sql) or die('Error updating picks summary: ' mysql_error());
        
    $sql "insert into " $db_prefix "picksummary (weekNum, userID, showPicks) values (" $_POST['week'] . ", " $user->userID ", " . (int)$_POST['showPicks'] . ");";
        
    mysql_query($sql) or die('Error updating picks summary: ' mysql_error());
        
        
    //loop through non-expire weeks and update picks
        
    $sql "select * from " $db_prefix "schedule where weekNum = " $_POST['week'] . " and (DATE_ADD(NOW(), INTERVAL " SERVER_TIMEZONE_OFFSET " HOUR) < gameTimeEastern and DATE_ADD(NOW(), INTERVAL " SERVER_TIMEZONE_OFFSET " HOUR) < '" $cutoffDateTime "');";
        
    $query mysql_query($sql);
        while (
    $result mysql_fetch_array($query)) {
            
    $sql "delete from " $db_prefix "picks where userID = " $user->userID " and gameID = " $result['gameID'];
            
    mysql_query($sql) or die('Error deleting picks: ' mysql_error());
            
            if (!empty(
    $_POST['game' $result['gameID']])) {
                
    $sql "insert into " $db_prefix "picks (userID, gameID, pickID) values (" $user->userID ", " $result['gameID'] . ", '" $_POST['game' $result['gameID']] . ");
                              update " 
    $db_prefix "picks SET 'points' = "intval($_POST['points' $result['gameID']]) ." WHERE 'userID' = "$user ." and 'gameID' = "$result['gameID'] ." LIMIT 1 ;";
                
    mysql_query($sql) or die('Error inserting pick: ' mysql_error()); 
            }
        }
        
    header('Location: results.php?week=' $_POST['week']);
    } else {
        
    $week = (int)$_GET['week'];
        if (empty(
    $week)) {
            
    //get current week
            
    $week = (int)getCurrentWeek();
        }
        
    $cutoffDateTime getCutoffDateTime($week);
        
    $firstGameTime getFirstGameTime($week);
    }

    include(
    'includes/header.php');
    include(
    'includes/column_right.php');

    //display week nav
    $sql "select distinct weekNum from " $db_prefix "schedule order by weekNum;";
    $query mysql_query($sql);
    $weekNav '<div class="navbar3"><b>Go to week:</b> ';
    $i 0;
    while (
    $result mysql_fetch_array($query)) {
        if (
    $i 0$weekNav .= ' | ';
        if (
    $week !== (int)$result['weekNum']) {
            
    $weekNav .= '<a href="entry_form.php?week=' $result['weekNum'] . '">' $result['weekNum'] . '</a>';
        } else {
            
    $weekNav .= $result['weekNum'];
        }
        
    $i++;
    }
    $weekNav .= '</div>' "\n";
    echo 
    $weekNav;
    ?>
    <!--
        <table cellpadding="0" cellspacing="0">
            <tr valign="top">
                <td width="60%">
    //-->
                    <h2>Week <?php echo $week?> - Make Your Picks:</h2>
                    <p>Make your picks below by clicking on the team helmet or checking the radio buttons to the right.</p>
                    <script type="text/javascript">
                    function checkform() {
                        //make sure all picks have a checked value
                        var f = document.entryForm;
                        var allChecked = true;
                        var allR = document.getElementsByTagName('input');
                        for (var i=0; i < allR.length; i++) {
                            if(allR[i].type == 'radio') {
                                if (!radioIsChecked(allR[i].name)) {
                                    allChecked = false;
                                }
                            }      
                        }
                        if (!allChecked) {
                            return confirm('One or more picks are missing for the current week.  Do you wish to submit anyway?');
                        }
                        return true;
                    }
                    function radioIsChecked(elmName) {
                        var elements = document.getElementsByName(elmName);
                        for (var i = 0; i < elements.length; i++) {
                            if (elements[i].checked) {
                                return true;
                            }
                        }
                        return false;
                    }
                    </script>
        <div style="float: right; width: 270px; margin-right: 10px"><?php include('includes/comments.php'); ?></div>
        <?php
        
    //get existing picks
        
    $picks getUserPicks($week$user->userID);
        
    $points = array();
        
    $points $picks;

        
    //get show picks status
        
    $sql "select * from " $db_prefix "picksummary where weekNum = " $week " and userID = " $user->userID ";";
        
    $query mysql_query($sql);
        if (
    mysql_num_rows($query) > 0) {
            
    $result mysql_fetch_array($query);
            
    $showPicks = (int)$result['showPicks'];
        } else {
            
    $showPicks 1;
        }
        
        
    //display schedule for week
        
    $sql "select s.*, (DATE_ADD(NOW(), INTERVAL " SERVER_TIMEZONE_OFFSET " HOUR) > gameTimeEastern or DATE_ADD(NOW(), INTERVAL " SERVER_TIMEZONE_OFFSET " HOUR) > '" $cutoffDateTime "')  as expired ";
        
    $sql .= "from " $db_prefix "schedule s ";
        
    $sql .= "inner join " $db_prefix "teams ht on s.homeID = ht.teamID ";
        
    $sql .= "inner join " $db_prefix "teams vt on s.visitorID = vt.teamID ";
        
    $sql .= "where s.weekNum = " $week " ";
        
    $sql .= "order by s.gameTimeEastern, s.gameID";
        
    //echo $sql;
        
    $query mysql_query($sql);
        if (
    mysql_num_rows($query) > 0) {
            echo 
    '<form name="entryForm" action="entry_form.php" method="post" onsubmit="return checkform();">' "\n";
            echo 
    '<input type="hidden" name="week" value="' $week '" />' "\n";
            echo 
    '<table cellpadding="4" cellspacing="0" class="table1">' "\n";
            
    //echo '    <tr><th>Home</th><th>Visitor</th><th align="left">Game</th><th>Time / Result</th><th>Your Pick</th></tr>' . "\n";
            
    $i 0;
            while (
    $result mysql_fetch_array($query)) {
                
    $homeTeam = new team($result['homeID']);
                
    $visitorTeam = new team($result['visitorID']);
                
    $rowclass = (($i == 0) ? ' class="altrow"' '');
                
    //$pickExpired = ((date("U") > strtotime($result['gameTimeEastern'])) ? true : false);
                
    echo '        <tr' $rowclass '>' "\n";
                echo 
    '            <td align="center">' "\n";
                echo 
    '                <table width="100%" border="0" cellpadding="2" cellspacing="0" class="nostyle">' "\n";
                echo 
    '                    <tr valign="middle">' "\n";
                echo 
    '                        <td align="center"><label for="' $result['gameID'] . $visitorTeam->teamID '"><img src="images/helmets_big/' strtolower($visitorTeam->teamID) . '1.gif" onclick="document.entryForm.game' $result['gameID'] . '[0].checked=true;" /></label><br /><span style="font-size: 9px;"><b>' $visitorTeam->city ' ' $visitorTeam->team '</b><br />Record: ' getTeamRecord($visitorTeam->teamID) . '<br />Streak: ' getTeamStreak($visitorTeam->teamID) . '</span></td>' "\n";
                echo 
    '                        <td align="center">at</td>' "\n";
                echo 
    '                        <td align="center"><label for="' $result['gameID'] . $homeTeam->teamID '"><img src="images/helmets_big/' strtolower($homeTeam->teamID) . '2.gif" onclick="document.entryForm.game' $result['gameID'] . '[1].checked=true;" /></label><br /><span style="font-size: 9px;"><b>' $homeTeam->city ' ' $homeTeam->team '</b><br />Record: ' getTeamRecord($homeTeam->teamID) . '<br />Streak: ' getTeamStreak($homeTeam->teamID) . '</span></td>' "\n";
                echo 
    '                    </tr>' "\n";
                if (
    strlen($result['homeScore']) > && strlen($result['visitorScore']) > 0) {
                    
    //if score is entered, show score
                    
    echo '                    <tr><td colspan="3" align="center"><b>Final: ' $result['visitorScore'] . ' - ' $result['homeScore'] . '</b></td></tr>' "\n";
                } else {
                    
    //else show time of game
                    
    echo '                    <tr><td colspan="3" align="center">' date('D n/j g:i a'strtotime($result['gameTimeEastern'])) . ' ET</td></tr>' "\n";
                }
                echo 
    '                </table>' "\n";
                echo 
    '            </td>' "\n";
                echo 
    '            <td align="left"><b>Your Pick:</b><br />' "\n";
                if (!
    $result['expired']) {
                    
    //if game is not expired, show pick
                    
    echo '            <input type="radio" name="game' $result['gameID'] . '" value="' $visitorTeam->teamID '" id="' $result['gameID'] . $visitorTeam->teamID '"' . (($picks[$result['gameID']]['pickID'] == $visitorTeam->teamID) ? ' checked="checked"' '') . ' /> <label for="' $result['gameID'] . $visitorTeam->teamID '">' $visitorTeam->teamName '</label><br />' "\n";
                    echo 
    '            <input type="radio" name="game' $result['gameID'] . '" value="' $homeTeam->teamID '" id="' $result['gameID'] . $homeTeam->teamID '"' . (( $picks[$result['gameID']]['pickID'] == $homeTeam->teamID) ? ' checked="checked"' '') . ' /> <label for="' $result['gameID'] . $homeTeam->teamID '">' $homeTeam->teamName '</label><br />' "\n";
                    echo 
    '            <input type="number" min="1" max="15" name="points' $result['gameID'] . '" value="' $picks[$result['gameID']]['points']  . '"/><br />' "\n";                
                    
                } else {
                    
    //else show locked pick
                    
    $pickID getPickID($result['gameID'], $user->userID);
                    if (!empty(
    $pickID)) {
                        
    $statusImg '';
                        
    $pickTeam = new team($pickID);
                        
    $pickLabel $pickTeam->teamName;
                                  
                    } else {
                        
    $statusImg '<img src="images/cross_16x16.png" width="16" height="16" alt="" />';
                        
    $pickLabel 'None Selected';
                    }
                    if (
    $scoreEntered) {
                        
    //set status of pick (correct, incorrect)
                        
    if ($pickID == $result['winnerID']) {
                            
    $statusImg '<img src="images/check_16x16.png" width="16" height="16" alt="" />';
                        } else {
                            
    $statusImg '<img src="images/cross_16x16.png" width="16" height="16" alt="" />';
                        }
                    }
                    echo 
    '            ' $statusImg ' ' $pickLabel "\n";
                }
                echo 
    '            </td>' "\n";
                echo 
    '        </tr>' "\n";
                
    $i++;
            }
            echo 
    '</table>' "\n";
            echo 
    '<p><input type="checkbox" name="showPicks" id="showPicks" value="1"' . (($showPicks) ? ' checked="checked"' '') . ' /> <label for="showPicks">Allow others to see my picks</label></p>' "\n";
            echo 
    '<p><input type="submit" name="action" value="Submit" /></p>' "\n";
            echo 
    '</form>' "\n";
        }
        
    ?>
    <!--
                </td>
                <td width="40%">
                    <h2>Latest Comments:</h2>
                    <p>comment</p>
                    <div>
                    
                    </div>
                </td>
            </tr>
        </table>
    //-->
    <?php
    include('includes/footer.php'); 
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I'll show you how to go about troubleshooting something like this.

    Let's focus on this line ....

    update " . $db_prefix . "picks SET 'points' = ". intval($_POST['points' . $result['gameID']]) ." WHERE 'userID' = ". $user ." and 'gameID' = ". $result['gameID'] ." LIMIT 1 ;";

    Make a copy of it first and save it so you have the original line to look at later if needed.

    You're not sure if it's not updating points because the points value is not correct, or because the arguments for the WHERE are not correct.

    So start by forcing a known value in for points and see if that is working:

    update " . $db_prefix . "picks SET 'points' = 99 WHERE 'userID' = ". $user ." and 'gameID' = ". $result['gameID'] ." LIMIT 1 ;";

    If you see 99 entered successfully when done, then you know this part is not right:
    intval($_POST['points' . $result['gameID']])

    If you still don't see 99 entered, then look at this part:
    WHERE 'userID' = ". $user ." and 'gameID' = ". $result['gameID'] ." LIMIT 1 ;

    I'm also going to question the single-quotes around your column names.
    Maybe someone can tell us if those should be there or not. I would say not.

    This would be the line without the single quotes:
    update " . $db_prefix . "picks SET points = 99 WHERE userID = ". $user ." AND gameID = ". $result['gameID'] ." LIMIT 1 ;";

    You can experiment with that as well.

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The only reason the update is there, is it was not doing it when I had it in the above line as part of the insert statement.

    After beating my head against the wall all day, I started putting echo statements in, sleep to slow it down before redirecting, exits to see how far it was even getting and this is what has been discovered.

    It is not even getting inside of the if action= submit condition. However it is still somehow still writing the picks to the picks table (not points) and writing the fields showpicks to the pickssummary. If I put an exit; directly inside the if statement it never exits.

    I even put this above the 1st if and it still doesn't exit.
    PHP Code:
    if (isset($_POST['action']))
     {
     echo 
    $_POST['action']; 
     exit;
     } 
    If I put just an exit; above the if statement it does exit.

    So action is never holding anything?

    How is it still writing the pick fields?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    In the script you posted in the first post, is this the filename of that script? entry_form.php

    So you're showing us the script with the form, and that is the same script as the one that is writing to your database?

  • Users who have thanked mlseim for this post:

    abscooters (10-18-2013)

  • #5
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    entry_form.php is the original script where points where just a default 1. entry_formweighted.php is the one I am working on to try and pass inputted confidence weighted points to the table.

  • #6
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    In the script you posted in the first post, is this the filename of that script? entry_form.php

    So you're showing us the script with the form, and that is the same script as the one that is writing to your database?
    THANK YOU I think it just clicked


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •