Jump to content

why is $atBats undefined?


Hillary

Recommended Posts

<html>

 

<head>

<title></title>

</head>

<body>

 

 

<?php

print"<center>";

print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";

echo "<table width=500 cellspacing=10>\n";

$data = array();

$data = file("phillsstat.csv");

$record=array();

$i=0;

 

foreach($data as $line)

{

echo "  <tr>\n";

$field= explode(",",$line);

 

foreach($field as $value)

{

echo "    <td>$value</td>\n";

}

echo "  </tr>\n";

}

echo "</table>";

print"</center>";

print"<hr></hr>";

print "<center>";

print "<h3>Enter New Stats and press Update</h3>";

print "</center>";

 

//print_r($_GET);

//$avg=$past."=".$state;

$atbats= array();

$hits= array();

$avg= array();

 

if(isset($atBats))

{

$atBats[0]=0;

$atBats[1]=0;

$atBats[2]=0;

$atBats[3]=0;

$atBats[4]=0;

}

 

 

if(isset($hits))

{

$hits[0]=0;

$hits[1]=0;

$hits[2]=0;

$hits[3]=0;

$hits[4]=0;

}

 

$avg=$atBats[0]+$hits[0];

$avg=$atBats[1]+$hits[1];

$avg=$atBats[2]+$hits[2];

$avg=$atBats[3]+$hits[3];

$avg=$atBats[4]+$hits[4];

 

 

//print "<p> Past:$past.State$state</p>\n";

print "<center>";

print"<form>\n";

 

 

print"Rollins<input type=\"text\" \"hidden\" name=\"game[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$atBats[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$hits[0]\" value=\"\"><br />\n";

 

 

print"Howard<input type=\"text\" \"hidden\" name=\"game[1]\"> <input type=\"text\" \"hidden\" name=\"$atBats[1]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[1]\"><br />\n";

 

 

print"Burrell<input type=\"text\" \"hidden\" name=\"game[2]\"> <input type=\"text\" \"hidden\" name=\"$atBats[2]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[2]\"><br />\n";

 

 

print"Victorino<input type=\"text\" \"hidden\" name=\"game[3]\"> <input type=\"text\" \"hidden\" name=\"$atBats[3]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[3]\"><br />\n";

 

 

print"Utley<input type=\"text\" \"hidden\" name=\"game[4]\"> <input type=\"text\" \"hidden\" name=\"$atBats[4]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[4]\"><br />\n";

 

print"<input type=\"submit\" value=\"Update\">\n";

print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";

 

print "</form>\n";

print "</center>";

?>

 

 

 

 

 

 

 

 

 

Philadelphia Phillies 2008 Season Stats.

 

Player Game AtBats Hits Average

Rollins 4 18 5

Howard 4 14 3

Burrell 4 13 5

Victorino 4 15 2

Utley 4 14 5

Enter New Stats and press Update

 

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 62

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 63

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 64

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 65

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 66

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 74

Rollins 

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 77

Howard 

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 80

Burrell 

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 83

Victorino 

 

Notice: Undefined variable: atBats in C:\Inetpub\wwwroot\StudentWeb\WIS-120-SEN01-SPRING2008\student4\finalproject\phil.php on line 86

Utley 

 

 

 

 

 

this is the site its on if it makes things more readable... http://eno.wilmu.edu/WIS%2D120%2DSEN01%2DSPRING2008/student4/finalproject/phil.php

 

it looks fine when it comes from my computer but when its online atBats is undefined in multiple lines.

Link to comment
https://forums.phpfreaks.com/topic/101623-why-is-atbats-undefined/
Share on other sites

Corrected code:

 

 


<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form>\n";


print"Rollins<input type=\"text\" \"hidden\" name=\"game[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$atBats[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$hits[0]\" value=\"\">
\n";


print"Howard<input type=\"text\" \"hidden\" name=\"game[1]\"> <input type=\"text\" \"hidden\" name=\"$atBats[1]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[1]\">
\n";


print"Burrell<input type=\"text\" \"hidden\" name=\"game[2]\"> <input type=\"text\" \"hidden\" name=\"$atBats[2]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[2]\">
\n";


print"Victorino<input type=\"text\" \"hidden\" name=\"game[3]\"> <input type=\"text\" \"hidden\" name=\"$atBats[3]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[3]\">
\n";


print"Utley<input type=\"text\" \"hidden\" name=\"game[4]\"> <input type=\"text\" \"hidden\" name=\"$atBats[4]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[4]\">
\n";

print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";

print "</form>\n";
print "</center>";
?>


yeah i definitely stared at that for a long time trying to figure out what i did wrong... oooh case sensitive programming. one more question i have is how can i center the names and text input boxes across the page but keep the names aligned left? does that make sense? i want to have the names in one column i guess is what im saying?

Try using Tables:

 

 


<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$atBats[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$hits[0]\" value=\"\">
\n";
print"</td></tr>";


print"<tr><td valign=left>";
print"
Howard</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[1]\"> <input type=\"text\" \"hidden\" name=\"$atBats[1]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[1]\">
\n";
print"</td></tr>";

print"<tr><td valign=left>";
print"Burrell</td>"
print"<td valign=centet>
<input type=\"text\" \"hidden\" name=\"game[2]\"> <input type=\"text\" \"hidden\" name=\"$atBats[2]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[2]\">
\n";
print"</td></tr>";


print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[3]\"> <input type=\"text\" \"hidden\" name=\"$atBats[3]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[3]\">
\n";
print"</td></tr>";


print"<tr><td valign=left>Utley</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[4]\"> <input type=\"text\" \"hidden\" name=\"$atBats[4]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[4]\">
\n";
print"</td></tr></table>";

print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";

print "</form>\n";
print "</center>";
?>

Revised Code  was missing semi colons:

 

 


<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$atBats[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$hits[0]\" value=\"\">
\n";
print"</td></tr>";


print"<tr><td valign=left>";
print"
Howard</td>";
print"<td valign=center>
<input type=\"text\" \"hidden\" name=\"game[1]\"> <input type=\"text\" \"hidden\" name=\"$atBats[1]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[1]\">
\n";
print"</td></tr>";

print"<tr><td valign=left>";
print"Burrell</td>";
print"<td valign=centet>
<input type=\"text\" \"hidden\" name=\"game[2]\"> <input type=\"text\" \"hidden\" name=\"$atBats[2]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[2]\">
\n";
print"</td></tr>";


print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>";
<input type=\"text\" \"hidden\" name=\"game[3]\"> <input type=\"text\" \"hidden\" name=\"$atBats[3]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[3]\">
\n";
print"</td></tr>";


print"<tr><td valign=left>Utley</td>";
print"<td valign=center>";
print"
<input type=\"text\" \"hidden\" name=\"game[4]\"> <input type=\"text\" \"hidden\" name=\"$atBats[4]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[4]\">
\n";
print"</td></tr></table>";

print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";

print "</form>\n";
print "</center>";
?>

i forgot to put print before an input and it wouldnt work right with double quotes so i had to use a combo of double and single quotes for it

 

 

Also it is recognizing as game[] as an undefined index because it is expecting something like $game= array();

 

$game[]

 

 

code:

 

 

<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'game[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$atBats[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[0]'\" value=\"\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"
Howard</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'game[1]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[1]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[1]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"Burrell</td>";
print'<td valign=centet>
<input type=\"text\" \"hidden\" name=\"'game[2]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[2]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[2]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>";
print'<input type="text\" \"hidden\" name=\"'game[3]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[3]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[3]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Utley</td>";
print"<td valign=center>";
print'
<input type=\"text\" \"hidden\" name=\"'game[4]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[4]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[4]'\">
\n';
print"</td></tr></table>";
print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";
print "</form>\n";
print "</center>";
?>

Here is what you want this wil array game and make sure it is set ;D

 

<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();
$game=array();
if(isset($game))
{
$game[0]=0;
$game[1]=0;
$game[2]=0;
$game[3]=0;
$game[4]=0;
}

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$atBats[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[0]'\" value=\"\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"
Howard</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[1]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[1]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[1]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"Burrell</td>";
print'<td valign=centet>
<input type=\"text\" \"hidden\" name=\"'$game[2]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[2]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[2]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>";
print'<input type="text\" \"hidden\" name=\"'$game[3]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[3]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[3]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Utley</td>";
print"<td valign=center>";
print'
<input type=\"text\" \"hidden\" name=\"'$game[4]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[4]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[4]'\">
\n';
print"</td></tr></table>";
print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";
print "</form>\n";
print "</center>";
?>

<html>

 

<head>

<title></title>

</head>

<body>

<?php

print"<center>";

print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";

echo "<table width=500 cellspacing=10>\n";

$data = array();

$data = file("phillsstat.csv");

$record=array();

$i=0;

 

foreach($data as $line)

{

echo "  <tr>\n";

$field= explode(",",$line);

 

foreach($field as $value)

{

echo "    <td>$value</td>\n";

}

echo "  </tr>\n";

}

 

echo "</table>";

print"</center>";

print"<hr></hr>";

print "<center>";

print "<h3>Enter New Stats and press Update</h3>";

print "</center>";

 

//print_r($_GET);

$atBats= array();

$hits= array();

$avg= array();

$game= array();

$_SERVER['PHP_SELF'];

if(isset($game))

{

$game[0]="";

$game[1]="";

$game[2]="";

$game[3]="";

$game[4]="";

}

 

 

if(isset($atBats))

{

$atBats[0]="";

$atBats[1]="";

$atBats[2]="";

$atBats[3]="";

$atBats[4]="";

}

 

 

if(isset($hits))

{

$hits[0]="";

$hits[1]="";

$hits[2]="";

$hits[3]="";

$hits[4]="";

}

 

 

print "<center>";

print"<form>\n";

<form method="POST"action="$_SERVER['PHP_SELF']>";

 

print"<table><tr>";

print"<td valign=left>Rollins</td>";

print"<td valign=center>

<input type=\"text\" \"hidden\" name=\"$game[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$atBats[0]\" value=\"\"> <input type=\"text\" \"hidden\" name=\"$hits[0]\" value=\"\">

\n";

print"</td></tr>";

 

 

print"<tr><td valign=left>";

print"

Howard</td>";

print"<td valign=center>

<input type=\"text\" \"hidden\" name=\"$game[1]\"> <input type=\"text\" \"hidden\" name=\"$atBats[1]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[1]\">

\n";

print"</td></tr>";

 

print"<tr><td valign=left>";

print"Burrell</td>";

print"<td valign=center>

<input type=\"text\" \"hidden\" name=\"$game[2]\"> <input type=\"text\" \"hidden\" name=\"$atBats[2]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[2]\">

\n";

print"</td></tr>";

 

 

print"<tr><td valign=left>Victorino</td>";

print"<td valign=center>

<input type=text\" \"hidden\" name=\"$game[3]\"> <input type=\"text\" \"hidden\" name=\"$atBats[3]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[3]\">

\n";

print"</td></tr>";

 

 

print"<tr><td valign=left>Utley</td>";

print"<td valign=center>";

print"

<input type=\"text\" \"hidden\" name=\"$game[4]\"> <input type=\"text\" \"hidden\" name=\"$atBats[4]\" value\"\"> <input type=\"text\" \"hidden\" name=\"$hits[4]\">

\n";

print"</td></tr></table>";

 

</select>

print"<input type=\"submit\" value=\"Update\">\n";

print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";

</form>

 

print "</form>\n";

print "</center>";

 

 

$avg=$atBats[""]/$hits[""];

$avg=$atBats[""]/$hits[""];

$avg=$atBats[""]/$hits[""];

$avg=$atBats[""]/$hits[""];

$avg=$atBats[""]/$hits[""];

print "$atBats/$hits= $avg";

 

 

//foreach($item as $element)

//{

// print"<td>" .$element . "</td>";

//}

 

//print "</tr>\n";

//print "</table>\n";

//name at bats hits

 

//$avg=$item[2]/$item[1];

 

print "<h2>Avg: " .$avg ."</h2>";

 

//number format

 

$avg= number_format(3);

$avg=substr($avg,1);

?>

 

</body>

</html>

 

 

 

 

heres my code now i have place form method="POST" action="$_SERVER['PHP_SELF'] in where i thought it would belong, at the beginning of the form? it returns error on line 74 did i need to put it somewhere else?

Corrected Code:

[code<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();
$game=array();
if(isset($game))
{
$game[0]=0;
$game[1]=0;
$game[2]=0;
$game[3]=0;
$game[4]=0;
}

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}

$avg=$atBats[0]+$hits[0];
$avg=$atBats[1]+$hits[1];
$avg=$atBats[2]+$hits[2];
$avg=$atBats[3]+$hits[3];
$avg=$atBats[4]+$hits[4];


//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form method=POST action='"$_SERVER['PHP_SELF']"'>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$atBats[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[0]'\" value=\"\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"
Howard</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[1]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[1]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[1]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"Burrell</td>";
print'<td valign=centet>
<input type=\"text\" \"hidden\" name=\"'$game[2]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[2]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[2]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>";
print'<input type="text\" \"hidden\" name=\"'$game[3]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[3]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[3]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Utley</td>";
print"<td valign=center>";
print'
<input type=\"text\" \"hidden\" name=\"'$game[4]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[4]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[4]'\">
\n';
print"</td></tr></table>";
print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";
print "</form>\n";
print "</center>";
?>

gah my comp is messing up here it is

 

 

 

Corrected code:

 

 

<?php
print"<center>";
print "<h1>Philadelphia Phillies 2008 Season Stats.</h1>";
   echo "<table width=500 cellspacing=10>\n";
$data = array();
$data = file("phillsstat.csv");
$record=array();
$i=0;

foreach($data as $line)
{
   echo "  <tr>\n";
$field= explode(",",$line);

foreach($field as $value)
{
   echo "    <td>$value</td>\n";
}
   echo "  </tr>\n";
}
   echo "</table>";
print"</center>";
print"
--------------------------------------------------------------------------------
</hr>";
print "<center>";
print "<h3>Enter New Stats and press Update</h3>";
print "</center>";

//print_r($_GET);
//$avg=$past."=".$state;
$atBats= array();
$hits= array();
$avg= array();
$game=array();
if(isset($game))
{
$game[0]=0;
$game[1]=0;
$game[2]=0;
$game[3]=0;
$game[4]=0;
}

if(isset($atBats))
{
$atBats[0]=0;
$atBats[1]=0;
$atBats[2]=0;
$atBats[3]=0;
$atBats[4]=0;
}


if(isset($hits))
{
$hits[0]=0;
$hits[1]=0;
$hits[2]=0;
$hits[3]=0;
$hits[4]=0;
}



//print "<p> Past:$past.State$state</p>\n";
print "<center>";
print"<form method=POST action='"$_SERVER['PHP_SELF']"'>\n";

print"<table><tr>";
print"<td valign=left>Rollins</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$atBats[0]'\" value=\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[0]'\" value=\"\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"
Howard</td>";
print'<td valign=center>
<input type=\"text\" \"hidden\" name=\"'$game[1]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[1]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[1]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>";
print"Burrell</td>";
print'<td valign=centet>
<input type=\"text\" \"hidden\" name=\"'$game[2]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[2]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[2]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Victorino</td>";
print"<td valign=center>";
print'<input type="text\" \"hidden\" name=\"'$game[3]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[3]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[3]'\">
\n';
print"</td></tr>";
print"<tr><td valign=left>Utley</td>";
print"<td valign=center>";
print'
<input type=\"text\" \"hidden\" name=\"'$game[4]'\"> <input type=\"text\" \"hidden\" name=\"'$atBats[4]'\" value\"\"> <input type=\"text\" \"hidden\" name=\"'$hits[4]'\">
\n';
print"</td></tr></table>";
print"<input type=\"submit\" value=\"Update\">\n";
print"<input type=\"submit\" value=\"Undo Stat Changes\">\n";
print "</form>\n";
print "</center>";




$avg=($atBats[0]+$hits[0])/2;
$avg1=($atBats[1]+$hits[1])/2;
$avg2=($atBats[2]+$hits[2])/2;
$avg3=($atBats[3]+$hits[3])/2;
$avg4=($atBats[4]+$hits[4])/2;

print 'Avg:'
print$avg;
print"Avg2: $avg2";
print"Avg3:$avg3";
print"Avg4:$avg4";


?>

 

yes this works as in, it no longer displays an error message, but how do i actually get the form and action to work together? i can input information but nothing updates i press submit and the form is cleared... maybe i need to re-order my information? its something about exploding the file into an array but i did that... i explode phillsstat.csv into array $data i think.. no i made the variable $data = array empty... hmmm educate me on how to explode things if you can? what do i do?  ???

haku sorry to disagree with you but it should work fine the wya i had it no reason to eascpape unless it is going into a database  Tongue

 

First you disagree with me, then after I'm realizing I was right, you come up with two ways to do it and say to do it that way. I already gave a valid solution.

Archived

This topic is now archived and is closed to further replies.

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