Jump to content

blank page after submit


colickyboy

Recommended Posts

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?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

Try putting this code at the very top, and see what it shows:

 

print "<pre>";
print "_REQUEST contains:\n";
var_dump($_REQUEST);
print "_POST contains:\n";
var_dump($_REQUEST);
print "_GET contains:\n";
var_dump($_GET);
exit(0);

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>'; 
          }

 

- have you defined the $cols (Sorry if it is, it's hard to see your code without the code tag)

- I'm not sure with $_REQUEST, normally I always use $_POST[''] to get variable when the <form> using post method.

- try adding'@' infront of your variables, separate them, and check whether it is filled or not after posting. Sample is below:

@ $year = 2007;
@ $visitor = $_POST['visitor']; 
@ $home = $_POST['home']; 
@ $gameid = $_POST['gameid']; 
@ $gamedate = $_POST['gamedate']; 
@ $PHP_SELF = $_SERVER['PHP_SELF'];

if ($year=='') echo 'Empty year';
if //continue with other variables.

if it is empty then you know that the data fetching is not working between the post.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

I'm not sure. But after looking again your last code what I can think of is that the number of <td> between rows are different. And the <table> formatting is not correct.

 

- Are you sure it will be 13 <td> ? No more and no less?

- <input> should be put inside the <td> try format your table like this:

...
      echo "<table><tr><td colspan=13>";
      echo "<input type='hidden' name='count' value='" . $count . "'>";
      echo "<input type='hidden' name='date' value='" . $gamedate . "'></td></tr>";
...
          echo '<tr><td><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 colspan='14'><input type='submit' name='submit' value='Submit'><br /><br /></td></tr>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I've tried with a simple code and found out that not all html page could parse "data[0]" as variable. I've tested it with ISO format html and it couldn't get the post.

 

Coding wise, this won't work:

...
<input name="data[0]" >
...

<?
$data[0]=$_POST["data[0]"]; //returns error

 

Perhaps this is your problem.

Link to comment
Share on other sites

I've tried with a simple code and found out that not all html page could parse "data[0]" as variable. I've tested it with ISO format html and it couldn't get the post.

 

Coding wise, this won't work:

...
<input name="data[0]" >
...

<?
$data[0]=$_POST["data[0]"]; //returns error

 

Perhaps this is your problem.

 

sighs.

 

That of course would not work, data is converted to an array when the data is posted.

 

<?php
$data = $_POST['data'];
print_r($data);

echo '<br /> OR: ' . $data[0];
?>

 

@ $year = 2007;

@ $visitor = $_POST['visitor'];

@ $home = $_POST['home'];

@ $gameid = $_POST['gameid'];

@ $gamedate = $_POST['gamedate'];

@ $PHP_SELF = $_SERVER['PHP_SELF'];

 

Whoever posted that needs to learn how to do stuff the proper way, damn.

 

<?php
$PHP_SELF = $_SERVER['PHP_SELF'];
$year = 2007;

$visitor = isset($_POST['visitor'])?$_POST['visitor']:'';  // sets value to '' if the variable is not set.
$home = isset($_POST['home'])?$_POST['home']:''; 
$gameid = isset($_POST['gameid'])?$_POST['gameid']:''; 
$gamedate = isset($_POST['gamedate'])?$_POST['gamedate']:''; 

?>

 

Would be the "proper" way to set variables from post/get data.

 

On that note "notices" are exactly that, just a notice. They would not be the issue why the form data is not submitting. They would not be the cause.

 

As for the action being blank, there is no need you have PHP_SELF defined, use it. That may not be the problem, but certainly is not the ideal way to create a form.

 

<?php
      echo "<form method='POST' action='" . $PHP_SELF . "'>";
?>

 

Finally as the last resort setup a unit test, to figure out where it is going wrong.

 

post_test.php

<?php
if (isset($_POST['submit'])) {
   echo 'The data posted was:<br />', print_r($_POST), '<br />';
}

echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="POST"><input type="hidden" value="Test" name="testing" />
        <input type="text" value="This is just a test" size="30" name="MyTest" /><br />
       <input type="submit" value="Test me Out!" name="submit" /><br />
        </form>';
?>

 

Run that script on your server and see what happens. If you are getting output than it is an issue with the script somewhere, if you are not than the server is setup to access the $_POST differently. I would suggest trying $HTTP_POST_VARS  (although depreciated maybe the host decided to use those instead).

 

EDIT:::

 

After looking at this:

 

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

 

Change it to this and try the form.

 

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

 

HTML forms probably has a heartache about you trying to define the index in the array. Try it out and see how it goes.

 

 

EDIT Num2:

Here is the full code with the $i portion removed for easy trial:

 

<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[]" value="' . $id . '" />';
          echo '<input type="hidden" name="name[]" value="' . $name . '" />';
          echo '<input type="hidden" name="team[]" value="' . $team . '" />';
          echo '<input type="hidden" name="gameid[]" value="' . $gameid . '" /></td></tr>';
          echo "<tr><td>$name</td>";
          echo '<td><select name="battingorder[]">';
            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 . '[]" 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>";
?>

 

 

In Regards to brethl's post

I noticed that brethl did not explicitly state that you need to put that var_dump stuff inside the isset($_POST['submit'])  if portion as you were killing the script before you had a chance to enter any data, which is why it returned blank values.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Ummm yea, what I suggested earlier, try removing the $i out as it is not necessary.

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Than you are going about it wrong. HTML takes the [] as an array. That could very well be why your form is not working.

 

Try something like this:

 

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

 

Unsure if that will suit your needs, but yea the [] is definitely not right as HTML takes that as an array submission. As long as it starts at one and just increments you should be able to extract that data by doing something like this:

 

<?php
$i=1;
while (isset($_POST['id-' . $i])) {
     $ids[] = $_POST['id-' . $i];
     // .. etc for the rest of the fields
     $i++;
}
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.