Jump to content

colickyboy

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Posts posted by colickyboy

  1. unfortunately, i think i've stumped everyone.

     

    i created a form for one team instead of two teams to see if maybe too much data was causing the problem. indeed, a form for one team worked...except when a team's roster hits 19 people...then it stopped working again. so it does appear to be a limitation of how much data can be passed. does anyone know anything about this? there has to be a way around this b/c i'm sure others are submitting lots more data at a time than i am...

     

     

  2. Good catch on the spaces...I've changed that. However, it didn't fix the problem.

     

    It does seem like a lot of data being passed, but I've used this script last year without problems. That's part of what makes this maddening!

  3. here is the html source for 6 columns (this is for queried player #8):

     

      <td><input type="text" name="pos-8" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="ab-8" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="r-8" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="b1-8" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="b2-8" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="b3-8" align="top" maxlength="2" size="2" /></td>
    </tr>
    

  4. hi frost110,

     

    i'm actually not using the $i to define the index of the array. i'm using it to assign a number for each queried player so i can later post their stats without confusing which stats below to whom. here's the html source of the form that's generated... it may better explain what the generated form looks like:

     

    <tr>
      <td colspan="14">
        <input type="hidden" name="id[1]" value="197" />
        <input type="hidden" name="name[1]" value="Brian White" />
        <input type="hidden" name="team[1]" value="Rock Salt" />
        <input type="hidden" name="gameid[1]" value="40" />
      </td>
    </tr>
    <tr>
      <td>Brian White</td>
      <td><select name="battingorder[1]">
        <option value='' selected></option><br />
        <option value = '1'>1</option><br />
        <option value = '2'>2</option><br />
        ...
        <option value = '17'>17</option><br />
        </select>
      </td>
      <td><input type="text" name="pos[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="AB[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="R[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B1[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B2[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B3[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="HR[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="RBI[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="SF[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="BB[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="K[1]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="E[1]" align="top" maxlength="2" size="2" /></td>
    </tr>
    <tr>
      <td colspan="14">
        <input type="hidden" name="id[2]" value="193" />
        <input type="hidden" name="name[2]" value="Eric Liu" />
        <input type="hidden" name="team[2]" value="Rock Salt" />
        <input type="hidden" name="gameid[2]" value="40" />
      </td>
    </tr>
    <tr>
      <td>Eric Liu</td>
      <td><select name="battingorder[2]">
        <option value='' selected></option><br />
        <option value = '1'>1</option><br />
        ...
        <option value = '17'>17</option><br />
        </select>
      </td>
      <td><input type="text" name="pos[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="AB[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="R[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B1[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B2[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="B3[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="HR[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="RBI[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="SF[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="BB[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="K[2]" align="top" maxlength="2" size="2" /></td>
      <td><input type="text" name="E[2]" align="top" maxlength="2" size="2" /></td>
    </tr>
    

     

    When submitted, the code processes each player, keeping track of all the stats for each player by the index (each player is assigned an index number).

     

    i tried removing the $i as you suggested just for kicks and not surprisingly, that didn't work. for what it's worth, i did the post_test.php that you suggested, and i did get output.

  5. if i replace the foreach loop construct and hardcode 5 cols, it works...clicking submit brings a page that echos "hello"

     

    echo '<td><input type="text" name="pos[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="ab[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="r[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="b1[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="b2[' . $i . ']" align="top" maxlength="2" size="2" /></td>';

     

    but if i add a 6th col, it fails...clicking submit gives me a blank page again

     

    echo '<td><input type="text" name="pos[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="ab[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="r[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="b1[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="b2[' . $i . ']" align="top" maxlength="2" size="2" /></td>';
              echo '<td><input type="text" name="b3[' . $i . ']" align="top" maxlength="2" size="2" /></td>';

     

    so bizarre...any idea why this is happening?

  6. There are always 14 total <td>...12 from the array used in foreach, 1 for the batting order position, and 1 for the player's name.

     

    I adjusted the <input> tags to be inside <td> as follows:

     

    <div id='header'>Enter player results for <?php echo fdate($gamedate)?></div><br /><br />
    <?php
          $result = mysql_query("SELECT id, name, team FROM players WHERE team in ('$visitor','$home') AND year='$year' ORDER BY team, name");
          $count = mysql_num_rows($result);
          $teamck = "";
          $i = 1;
          echo "<form method='post' action=''>";
          echo "<table>";
          echo "<tr><td colspan='14'><input type='hidden' name='count' value='" . $count . "'>";
          echo "<input type='hidden' name='date' value='" . $gamedate . "'></td></tr>";
      while ($myrow = mysql_fetch_assoc($result)) {
        $id = $myrow["id"];
        $team = $myrow["team"];
        if ($teamck != $team) {
              echo "<tr><td colspan='14' align='center'>$team</td></tr> 
                      <tr>
                        <td>Name</td>
                        <td>Order</td>
                        <td>POS</td>
                        <td>AB</td>
                        <td>R</td>
                        <td>1B</td>
                        <td>2B</td>
                        <td>3B</td>
                        <td>HR</td>
                        <td>RBI</td>
                        <td>SF</td>
                        <td>BB</td>
                        <td>K</td>
                        <td>E</td>
                      </tr>";
            }
            if ($count > 0) {
              $name = $myrow["name"];
              echo '<tr><td colspan="14"><input type="hidden" name="id[' . $i . ']" value="' . $id . '" />';
              echo '<input type="hidden" name="name[' . $i . ']" value="' . $name . '" />';
              echo '<input type="hidden" name="team[' . $i . ']" value="' . $team . '" />';
              echo '<input type="hidden" name="gameid[' . $i . ']" value="' . $gameid . '" /></td></tr>';
              echo "<tr><td>$name</td>";
              echo '<td><select name="battingorder[' . $i .']">';
                echo "<option value='' selected></option><br />";
              for ($n = 1; $n <= 17; $n++){
                echo "<option value = '$n'>$n</option><br />";
              }
              echo "</select></td>";
              foreach ($cols as $col) {
                echo '<td><input type="text" name="' . $col . '[' . $i .']" align="top" maxlength="2" size="2" /></td>'; }
              echo "</tr>";
              $i++;
              $teamck = $team;
            }
          }    
          echo "<tr><td colspan='14'><input type='submit' name='submit' value='Submit'></td></tr><br /><br />";
          echo "</table></form>";

     

    Still doesn't work.

  7. thanks, thefortrees...but that's not necessary b/c the form works if i take out the little foreach code snippet. and i have another form page also with no form action (but no foreach code) that also works. just to cover all the bases, i tried declaring a specific form action anyway and it didn't work...still getting a blank page.

     

    apparently, this foreach line is causing the hiccup. i'm using php 4.4.6. i'm stumped what's wrong with the foreach line.

     

    mr_zhang, thanks for the suggestions. yes, i did define the $cols. and to eliminate the posting variables as a possible culprit, i replaced all the real actions upon submit and just told it to echo "hello" upon submit.

     

    the form displays properly with the foreach code...and looking at the source code it generates, it seems ok. but for some reason, clicking submit brings a blank page with the foreach code in, and "hello" echoed properly with the foreach code out!

  8. I'm really close I think...I've narrowed down the culprit to the following:

     

    foreach ($cols as $col) {
                echo '<td><input type="text" name="' . $col . '[' . $i .']" align="top" maxlength="2" size="2" /></td>'; 
              }

     

    If I take out this snippet, the form works and I don't get a blank page after submit. This snippet is part of this block of code:

     

    <div id='header'>Enter player results for <?php echo fdate($gamedate)?></div><br /><br />
    <?php
          $result = mysql_query("SELECT id, name, team FROM players WHERE team in ('$visitor','$home') AND year='$year' ORDER BY team, name");
          $count = mysql_num_rows($result);
          $teamck = "";
          $i = 1;
          echo "<form method='post' action=''>";
          echo "<table>";
          echo "<input type='hidden' name='count' value='" . $count . "'>";
          echo "<input type='hidden' name='date' value='" . $gamedate . "'>";
      while ($myrow = mysql_fetch_assoc($result)) {
        $id = $myrow["id"];
        $team = $myrow["team"];
        if ($teamck != $team) {
              echo "<tr><td colspan='13' align='center'>$team</td></tr> 
                      <tr>
                        <td>Name</td>
                        <td>Order</td>
                        <td>POS</td>
                        <td>AB</td>
                        <td>R</td>
                        <td>1B</td>
                        <td>2B</td>
                        <td>3B</td>
                        <td>HR</td>
                        <td>RBI</td>
                        <td>SF</td>
                        <td>BB</td>
                        <td>K</td>
                        <td>E</td>
                      </tr>";
            }
            if ($count > 0) {
              $name = $myrow["name"];
              echo '<input type="hidden" name="id[' . $i . ']" value="' . $id . '" />';
              echo '<input type="hidden" name="name[' . $i . ']" value="' . $name . '" />';
              echo '<input type="hidden" name="team[' . $i . ']" value="' . $team . '" />';
              echo '<input type="hidden" name="gameid[' . $i . ']" value="' . $gameid . '" />';
              echo "<tr><td>$name</td>";
              echo '<td><select name="battingorder[' . $i .']">';
                echo "<option value='' selected></option><br />";
              for ($n = 1; $n <= 17; $n++){
                echo "<option value = '$n'>$n</option><br />";
              }
              echo "</select></td>";
              foreach ($cols as $col) {
                echo '<td><input type="text" name="' . $col . '[' . $i .']" align="top" maxlength="2" size="2" /></td>'; 
              }
              echo "</tr>";
              $i++;
              $teamck = $team;
            }
          }    
          echo "<tr><td colspan='14'><input type='submit' name='submit' value='Submit'></td></tr><br /><br />";
          echo "</table></form>";

     

    However, I don't see anything wrong with the foreach syntax...or is there?

  9. It says:

     

    Notice: Undefined index: visitor in /gamestats.php on line 19
    Notice: Undefined index: home in /gamestats.php on line 20
    Notice: Undefined index: gameid in /gamestats.php on line 21
    Notice: Undefined index: gamedate in /gamestats.php on line 22
    

     

    which relate to:

    $visitor = $_REQUEST['visitor']; 
    $home = $_REQUEST['home']; 
    $gameid = $_REQUEST['gameid']; 
    $gamedate = $_REQUEST['gamedate']; 
    

     

    I tried fiddling with these but it got worse. Advice?

     

  10. I have a page that takes input for softball stats and then updates two mysql databases. This page worked last year but this year generates a blank page after clicking Submit and no databases are updated.

     

    Here is the code, all on one page (gamestats.php):

     

    $year = 2007;
    $visitor = $_REQUEST['visitor']; 
    $home = $_REQUEST['home']; 
    $gameid = $_REQUEST['gameid']; 
    $gamedate = $_REQUEST['gamedate']; 
    $PHP_SELF = $_SERVER['PHP_SELF'];
    
    function fdate($date) { 
          $mdy=explode("-", $date); 
          $Yr=$mdy[0]; $Mo=$mdy[1]; $Dy=$mdy[2]; 
          $newtime=date("l, M j, Y", mktime(0,0,0,$Mo,$Dy,$Yr)); 
          return $newtime; 
        }
    
    $cols = array('pos','AB','R','B1','B2','B3','HR','RBI','SF','BB','K','E');
    if (isset($_POST['submit'])) {
    
    // update players' game stats
    
      $count = $_POST["count"];
      $id = $_POST["id"];
      
      //$name = $_POST["name"];
    
      for ($i = 1; $i <= $count; $i++) {
    echo 'id[' . $i . '] = ' . $_POST['id'][$i] . "<br>";
    echo "date = " . $_POST['date'] . "<br>";
    echo 'name[' . $i . '] = ' . $_POST['name'][$i] . "<br>";
    echo 'team[' . $i . '] = ' . $_POST['team'][$i] . "<br>";
    echo 'opp[' . $i . '] = ' . $_POST['opp'][$i] . "<br>";
    echo 'battingorder[' . $i . '] = ' . $_POST['battingorder'][$i] . "<br>";
    echo 'pos[' . $i . '] = ' . $_POST['pos'][$i] . "<br>";
        echo 'AB[' . $i . '] = ' . $_POST['AB'][$i] . "<br>";
        echo 'R[' . $i . '] = ' . $_POST['R'][$i] . "<br>";
        echo 'B1[' . $i . '] = ' . $_POST['B1'][$i] . "<br>";
        echo 'B2[' . $i . '] = ' . $_POST['B2'][$i] . "<br>";
        echo 'B3[' . $i . '] = ' . $_POST['B3'][$i] . "<br>";
        echo 'HR[' . $i . '] = ' . $_POST['HR'][$i] . "<br>";
        echo 'RBI[' . $i . '] = ' . $_POST['RBI'][$i] . "<br>";
        echo 'SF[' . $i . '] = ' . $_POST['SF'][$i] . "<br>";
        echo 'BB[' . $i . '] = ' . $_POST['BB'][$i] . "<br>";
        echo 'K[' . $i . '] = ' . $_POST['K'][$i] . "<br>";
        echo 'E[' . $i . '] = ' . $_POST['E'][$i] . "<br>";
        
        
        $qtmp = array();
        $qtmp2 = array();
        foreach ($_POST as $k => $dmy)
           switch($k) {
               // case 'G':
               //     $qtmp[] = 'G = G + 1';
               //     break;
                case 'submit':
                case 'count':
                case 'id':
                case 'name':
                case 'team':
                case 'gameid':
                case 'date':
                case 'pos':
                case 'battingorder':
                
    //
    //   do nothing
    //
                     break;
                default: // all other fields
                     if ($_POST[$k][$i] != '') {
                   $qtmp[] = $_POST[$k][$i];
                   $qtmp2[] = $k . '=' . $k . '+' . $_POST[$k][$i];
                     }
                     break;
        }
        if (!empty($qtmp)) {
          $q = "INSERT INTO gamestats (name, date, team, gameid, battingorder, pos, AB, R, B1, B2, B3, HR, RBI, SF, BB, K, E) VALUES ('" . $_POST['name'][$i] . "', '" . $_POST['date'] . "', '" . $_POST['team'][$i] . "', '" . $_POST['gameid'][$i] . "', '" . $_POST['battingorder'][$i] . "', '" . $_POST['pos'][$i] . "', " . implode(', ',$qtmp) . ")";
          $result = mysql_query($q) or die("Problem updating DB, query: $q<br>" . mysql_error());
        }
        if (!empty($qtmp2)) {
          $q = "UPDATE players SET G=G+1, " . implode(', ',$qtmp2) . " where id=" . $_POST['id'][$i];
          $result = mysql_query($q) or die("Problem updating DB, query: $q<br>" . mysql_error());
        }
      }
    
      echo "Game results entered.";
    
    } else {
    
        if (!$gamedate) {
          echo "<div id='header'>MCSN Softball Update Central</div><br><br>";
          $result = mysql_query("SELECT id, date, visitor, home FROM gameresults WHERE year='$year' AND date <= curdate() ORDER BY date");
          if ($myrow = mysql_fetch_array($result)) {
        printf("<ul>");
        do {
    	  $gameid = $myrow["id"];
    	  $date = $myrow["date"];
    	  $visitor = $myrow["visitor"];
    	  $home = $myrow["home"];
              printf("<li type='square'><a href=\"%s?gamedate=%s&visitor=%s&home=%s&gameid=%s\">%s: %s at %s</a><br> \n", $PHP_SELF, $date, $visitor, $home, $gameid, fdate($date), $visitor, $home);
              echo "<br><br>";
            } while ($myrow = mysql_fetch_array($result));
          printf("</ul></div>");
          }
        }
        
    
        if ($gamedate) {
    ?>
      <form method="post" action="">
      <div id='header'>Enter player results for <?php echo fdate($gamedate)?></div><br><br>
    <?php
          $result = mysql_query("SELECT id, name, team FROM players WHERE team in ('$visitor','$home') AND year='$year' ORDER BY team, name");
          $count = mysql_num_rows($result);
          echo "<table>";
          $teamck = "";
          $i = 1;
      while ($myrow = mysql_fetch_assoc($result)) {
        $id = $myrow["id"];
        $team = $myrow["team"];
        if ($teamck != $team) {
              echo "<tr><td colspan='13' align='center'>$team</td></tr> 
                      <tr>
                        <td>Name</td>
                        <td>Order</td>
                        <td>POS</td>
                        <td>AB</td>
                        <td>R</td>
                        <td>1B</td>
                        <td>2B</td>
                        <td>3B</td>
                        <td>HR</td>
                        <td>RBI</td>
                        <td>SF</td>
                        <td>BB</td>
                        <td>K</td>
                        <td>E</td>
                      </tr>";
            }
            if ($count > 0) {
              
              $name = $myrow["name"];
              echo '<input type="hidden" name="id[' . $i . ']" value="' . $id . '">';
              echo '<input type="hidden" name="name[' . $i . ']" value="' . $name . '">';
              echo '<input type="hidden" name="team[' . $i . ']" value="' . $team . '">';
              echo '<input type="hidden" name="gameid[' . $i . ']" value="' . $gameid . '">';
              echo "<tr><td>$name</td>";
              //echo "<td><input type='text' name='" . $pos . "[" . $i . "]' align='top' maxlength='2' size='2'></td>";
              echo '<td><select name="battingorder[' . $i .']">';
                echo "<option value='' selected></option><br>";
              for ($n = 1; $n <= 17; $n++){
                echo "<option value = '$n'>$n</option><br>";
              }
              echo "</select></td>";
              foreach ($cols as $col)
                echo '<td><input type="text" name="' . $col . '[' . $i .']" align="top" maxlength="2" size="2"></td>';
              echo "</tr>";
              $i++;
              $teamck = $team;
            }
          }
          echo "</table>";
          echo '<input type="hidden" name="count" value="' . $count . '">';
          echo '<input type="hidden" name="date" value="' . $gamedate . '">';
          echo '<input type="submit" name="submit" value="Submit"><br><br>';
          echo '</form>';
        }
    }
    ?>
    

     

    This year I'm on PHP 4.4.6. Don't remember what I was on last year.

     

    I asked my ISP if it was an environment issue with the change to PHP 4.4.6 and they said it's a coding issue. What's wrong with the code that makes it not submit?

  11. I have a site that used iframes to call external files via the src attribute. I've since changed my code to comply with XHTML 1.0 transitional and iframes are not supported.

    I thought I could replace the iframe with CSS (overflow: auto) and use a PHP include...and it worked except for the major fact that it broke my menus.

    My original setup was:

    menu.php:
      <a href="?page=contact">Contact Us</a>

    main.php:
      $page=$_GET["page"];

      if ($page=="contact") {echo '<iframe scrolling="auto" src="contact.php"></iframe>';}

    So when a user clicked the "Contact Us" link, they would be on the contact.php page.

    But when I replaced that code with a PHP include:

    main.php:
      if ($page=="contact") {
      echo '<div class="iframe">';
      include("contact.php");
      echo '</div>';
    }

    the user was actually on the index.php page. Not only did this hose my contact page, but it also caused any page in my site that referenced a relative path to be off since the URL was no longer (for example) [b]correctpage.php?id=777[/b] but instead [b]index.php/correctpage.php?id=777[/b].

    I realize that "include" merely substitutes code from the external file, leaving the URL the same as the calling URL...whereas the SRC attribute in the iframe tag was actually calling the external file. So my question is: Is there a way to call an external file without using an iframe?

    As an aside, I tried the <OBJECT> tag:
    echo '<object type="text/html" data="contact.php" class="iframe"></object>';
    ...and it worked except that the page lost all style info from my external css file. I'm hoping there's a relatively painless PHP way to actually call an external file and thereby still retain reference to the css file.
  12. I have a players.php page with links like this:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]echo "<td><a href='stats.php?name=$name'><b>$name</b></a></td>";[/quote]

    In stats.php, I have this:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$name = $_GET['$name'];
    echo "name = $name";

    $query ="SELECT RBI FROM playerstats WHERE name='$name'";
    $result = mysql_query ($query) or die (mysql_error());
    $myrow = mysql_fetch_array($result);
    echo "RBI: " . $row["RBI"];[/quote]

    $name is echoing nothing.

    also tried
    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$name = $HTTP_GET_VARS['$name'];
    [/quote]
    and still $name is echoing nothing.

    This is driving me batty! (no pun intended) Should be simple, right but I'm not pulling in the querystring. Help please!
  13. Before I did that, I was getting this error:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]id[1] = 2
    AB[1] = 3
    R[1] = 3
    B1[1] = 3
    B2[1] = 0
    B3[1] = 0
    HR[1] = 0
    RBI[1] = 3
    SF[1] = 0
    BB[1] = 0
    K[1] = 0
    E[1] = 3
    Problem updating DB, query: UPDATE players SET G=G+1, AB=AB+3, R=R+3, B1=B1+3, B2=B2+0, B3=B3+0, HR=HR+0, RBI=RBI+3, SF=SF+0, BB=BB+0, K=K+0, E=E+3, count=count+ where id=2
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id=2' at line 1[/quote]

    When I added the lines you suggested, I got this error:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]id[1] = 2
    AB[1] = 6
    R[1] = 6
    B1[1] = 6
    B2[1] = 0
    B3[1] = 0
    HR[1] = 0
    RBI[1] = 6
    SF[1] = 0
    BB[1] = 0
    K[1] = 0
    E[1] = 6
    id[2] = 1
    AB[2] =
    R[2] =
    B1[2] =
    B2[2] =
    B3[2] =
    HR[2] =
    RBI[2] =
    SF[2] =
    BB[2] =
    K[2] =
    E[2] =
    Problem updating DB, query: UPDATE players SET G=G+1, AB=AB+, R=R+, B1=B1+, B2=B2+, B3=B3+, HR=HR+, RBI=RBI+, SF=SF+, BB=BB+, K=K+, E=E+ where id=1
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' R=R+, B1=B1+, B2=B2+, B3=B3+, HR=HR+, RBI=RBI+, SF=SF+, BB=BB+, K=K+, E=E+ wher' at line 1[/quote]

    I seem to be losing all the variable data in the update query now. As a wild guess, I tried adding a BREAK; after each line but that didn't work.

    The code now looks like this:
    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$qtmp = array();
    foreach ($_POST as $k => $dmy)
    switch($k) {
    // case 'G':
    // $qtmp[] = 'G = G + 1';
    // break;
    case 'id':
    case 'submit':
    case 'count':

    //
    // do nothing
    //
    break;
    default: // all other fields
    $qtmp[] = $k . '=' . $k . '+' . $_POST[$k][$i];
    break;
    }
    $q = "UPDATE players SET G=G+1, " . implode(', ',$qtmp) . " where id=" . $_POST['id'][$i];[/quote]

    How do I fix this?
  14. I got NAME out of the update query...now trying to figure out how to get the COUNT out of the update query, and how to get the "G=G+1" into it.

    Here's what I have so far:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php

    $cols = array('AB','R','B1','B2','B3','HR','RBI','SF','BB','K','E');
    if (isset($_POST['submit'])) {

    // update players' stats

    $count = $_POST["count"];
    $id = $_POST["id"];

    for ($i = 1; $i <= $count; $i++) {
    echo 'id[' . $i . '] = ' . $_POST['id'][$i] . "<br>";
    echo 'AB[' . $i . '] = ' . $_POST['AB'][$i] . "<br>";
    echo 'R[' . $i . '] = ' . $_POST['R'][$i] . "<br>";
    echo 'B1[' . $i . '] = ' . $_POST['B1'][$i] . "<br>";
    echo 'B2[' . $i . '] = ' . $_POST['B2'][$i] . "<br>";
    echo 'B3[' . $i . '] = ' . $_POST['B3'][$i] . "<br>";
    echo 'HR[' . $i . '] = ' . $_POST['HR'][$i] . "<br>";
    echo 'RBI[' . $i . '] = ' . $_POST['RBI'][$i] . "<br>";
    echo 'SF[' . $i . '] = ' . $_POST['SF'][$i] . "<br>";
    echo 'BB[' . $i . '] = ' . $_POST['BB'][$i] . "<br>";
    echo 'K[' . $i . '] = ' . $_POST['K'][$i] . "<br>";
    echo 'E[' . $i . '] = ' . $_POST['E'][$i] . "<br>";

    $qtmp = array();
    foreach ($_POST as $k => $dmy)
    switch($k) {
    case 'G':
    $qtmp[] = 'G = G + 1';
    break;
    case 'id':
    case 'submit':
    //
    // do nothing
    //
    break;
    default: // all other fields
    $qtmp[] = $k . '=' . $k . '+' . $_POST[$k][$i];
    break;
    }
    $q = "UPDATE players SET " . implode(', ',$qtmp) . " where id=" . $_POST['id'][$i];
    $result = mysql_query($q) or die("Problem updating DB, query: $q<br>" . mysql_error());
    }

    echo "Game results entered.";

    } else {

    echo "<div id='sectionheader'>Softball Update</div><br><br>";
    $result = mysql_query("SELECT id, name FROM players WHERE team='Barons' AND year=2006 ORDER BY name");
    $count = mysql_num_rows($result);
    echo '<form method="post" action="">';
    if ($count > 0) {
    $i = 1;
    echo "<table><tr><td colspan='13' align='center'>Barons</td></tr>
    <tr>
    <td>ID</td>
    <td>Name</td>
    <td>AB</td>
    <td>R</td>
    <td>1B</td>
    <td>2B</td>
    <td>3B</td>
    <td>HR</td>
    <td>RBI</td>
    <td>SF</td>
    <td>BB</td>
    <td>K</td>
    <td>E</td>
    </tr>";

    while ($myrow = mysql_fetch_assoc($result)) {
    $id = $myrow["id"];
    $name = $myrow["name"];
    echo '<input type="hidden" name="id[' . $i . ']" value="' . $id . '">';
    echo "<tr><td>$id</td>";
    echo "<td>$name</td>";
    foreach ($cols as $col)
    echo '<td><input type="text" name="' . $col . '[' . $i .']" align="top" maxlength="2" size="2"></td>';
    echo "</tr>";
    $i++;
    }
    echo "</table>";
    }


    echo '<input type="hidden" name="count" value="' . $count . '">';
    echo '<input type="submit" name="submit" value="Submit"><br><br>';
    echo '</form>';

    }
    ?>[/quote]
  15. thanks, kenrbnsn. you've gotten me 95% of the way there. right now, the generated mysql query is also trying to update NAME and COUNT. If I can exclude those variables from the update query and add the "G = G+1" line into the query, then I'm golden. Unfortunately, your technically svelte query is now out of my league so I don't know how to do it myself. Please advise.

    Thanks much!
  16. Thanks...no errors now. However, still not posting to the db. I suspect my $count hidden variable from the form is not being passed through or something of that sort b/c when I echo it after submitting, it comes back empty.

    What is wrong with the way the $count variable is being passed?
  17. Thanks. This is what I've got now:

    [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if ($_POST['submit']) {

    // update players' stats

    $count = $_POST['count'];

    for ($i = 1; $i <= $count; $i++) {
    [b]${"id".$i} = $_POST[id$i];[/b]
    ${"AB".$i} = $_POST[AB$i];
    ${"R".$i} = $_POST[R$i];
    ${"1B".$i} = $_POST[1B$i];
    ${"2B".$i} = $_POST[2B$i];
    ${"3B".$i} = $_POST[3B$i];
    ${"HR".$i} = $_POST[HR$i];
    ${"RBI".$i} = $_POST[RBI$i];
    ${"SF".$i} = $_POST[SF$i];
    ${"BB".$i} = $_POST[BB$i];
    ${"K".$i} = $_POST[K$i];
    ${"E".$i} = $_POST[E$i];

    $result = mysql_query('UPDATE players SET G=G+1, AB=AB+${"AB".$i}, R=R+${"R".$i}, 1B=1B+${"1B".$i}, 2B=2B+${"2B".$i}, 3B=3B+${"3B".$i}, HR=HR+${"HR".$i}, RBI=RBI+${"RBI".$i}, SF=SF+${"SF".$i}, BB=BB+$${"BB".$i}, K=K+${"K".$i}, E=E+${"E".$i} WHERE id=${"id".$i}');
    }[/quote]

    And I'm getting [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: syntax error, unexpected T_VARIABLE, expecting ']'[/quote] for the line in bold above...?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.