PHP Index problem

Hi,

I am using Apache2 and PHP 5.3.2 to create a website. With Ubuntu Linux 10.04 this works as expected. I attempted to copy the files to a laptop using XAMPP but the results were bad. I noticed that XAMPP uses php 5.3.1 and thought I need to upgrade the PHP version. After downloading WAMPSERVER and trying again, I was successful in downloading version 5.3.2 and confirmed that it is really running using phpinfo().

Now for the problem…


<html>
<title>Bingo Reporting System</title>
<body>
<h1>
<center>
<h1>Bingo Reporting System</h1>

<HR WIDTH="80%">
<h2>
<?php
require 'bingodatabase.php';


$sql = "select * from control where ID = 'A'";

$query = mysql_query($sql);
?>
<CENTER>
<?php

while ($row = mysql_fetch_array($query)) {

  echo $row['OrganizationName'];
  }
?>
<hr width="80%">

<table align=center>
<TR align=center><TD>&nbsp;</TD><TD>&nbsp;</TD><TD align=right>----------</TD><TD align=center>PROFIT</TD><TD align=left>----------</TD>
<tr align=center><td>DATE</td><td>PLAYERS</TD><TD>BINGO</TD><TD>TEARCARD</TD><TD>TOTAL</TD></TR>
<?php
$sql = "select * from gamedata";
$query2 = mysql_query($sql);
?>
<form action="bingoinsertgamedate.php" method="POST">
    <button type="submit" name="submit" value="addnew">Insert New Date</button>
</form>

<hr width="80%">

<form action="bingoeditgamedate.php" method="POST">

<?php
while ($row = mysql_fetch_array($query2)) {
  echo "<tr align=center><td>";
  ?>
  <button type="submit" name="submit" value="
  <?php
  echo $row['GameDate'];
  ?>
  ">
  <?php
  echo $row['GameDate'];
  echo "</button>";
  $pl = $row[3] + $row[4] + $row[5] + $row[6];
  $pl = $pl + $row[7] + $row[8] + $row[9] + $row[10];
  echo "</td><td>";
  echo $pl;
  $bpr = $row[1]+$row[2]+$row[11]+$row[12]+$row[13]+$row[14]+$row[15]+$row[16]+$row[17];
  $bpr = $bpr+$row[18]+$row[19]+$row[20]+$row[21]-$row[22];
  echo "</td><td>";
  echo number_format($bpr,2);
  echo "</td><td>";
  $tpr = $row[27]-$row[29];
  echo number_format($tpr,2);
  echo "</td><td>";
  $cpr = $bpr + $tpr;
  echo number_format($cpr,2);
  echo "</td></tr>";
}

?>
</form>
</TABLE>

<hr width="80%">
    <form action="bingoinsertgamedate.php" method="POST">
    <button type="submit" name="submit" value="addnew">Insert New Date</button>
    </form>

    <hr width="80%">

    <form action="bingoindex.php" method="POST">
    <button type="submit" name="__submit__" value="submit">
    (c) Copyright 2009 RDG Computer Services, 46 High Street, Newport ME 04953 
    -- All Rights Reserved
    </button>
    </form>
    </center>
<?php
mysql_close($dbh);
?>
</body>
</html>

This results in data appearing on the webpage with my Ubuntu setup, but with WAMP and XAMPP I get the following:

Notice: Undefined offset: 4 in c:\wamp\www\bingo\bingoviewgamedates.php on line 55
Notice: Undefined offset: 5 in c:\wamp\www\bingo\bingoviewgamedates.php on line 55
Notice: Undefined offset: 8 in c:\wamp\www\bingo\bingoviewgamedates.php on line 56
Notice: Undefined offset: 11 in c:\wamp\www\bingo\bingoviewgamedates.php on line 59
Notice: Undefined offset: 14 in c:\wamp\www\bingo\bingoviewgamedates.php on line 59
Notice: Undefined offset: 17 in c:\wamp\www\bingo\bingoviewgamedates.php on line 59
Notice: Undefined offset: 20 in c:\wamp\www\bingo\bingoviewgamedates.php on line 60
Notice: Undefined offset: 21 in c:\wamp\www\bingo\bingoviewgamedates.php on line 60
Notice: Undefined offset: 22 in c:\wamp\www\bingo\bingoviewgamedates.php on line 60
Notice: Undefined offset: 27 in c:\wamp\www\bingo\bingoviewgamedates.php on line 64
Notice: Undefined offset: 29 in c:\wamp\www\bingo\bingoviewgamedates.php on line 64

These errors repeat for each pass through the loop reading data from the database.

Does anyone know why this works in Linux but fails in Windows? I really need a way to make it work in both Windows and Linux.

You’re correct, JavaScript would be a challenge, but I am actually using SUBMIT “buttons” in HTML, not JavaScript. FireFox works as expected with 2 submit buttons of the same name with different value=“” parameters but Internet Explorer seems to have difficulty with this. I’m going to recode using 2 different name= parameters and test to see which button was clicked instead of the value passed in the button.

Thanks.

I actually put this inside my script that opens the database. Since I do this at the top of every .php file I thought it would be a quick and easy way to find errors. It showed an error where I pass gamedate via POST but look for _gamedate when I retrieve the data on the next page. After fixing the page I get the message “Abort Changes Update aborted!X” instead of having new data inserted when clicking the “Add Game Data” button on the page above. Still, being able to find errors will make debugging a simpler process. Thanks.

At the top of your script, place the following…


<?php
error_reporting(-1);
ini_set('display_errors', true);
?>

Note, this will show all errors/notices, allowing you to code well.

Not exactly sure how I fixed this, maybe the MySql server wasn’t running when I tested it (didn’t change anything yet) but the site still doesn’t work correctly. AT the bottom of the next form are two buttons: “Add Game Data” and “Abort Changes”. Clicking either has the expected result in Linux, but in Windows it acts as if “Abort Changes” was clicked no matter which is clicked. The code used for this is:

<html>
<title>Bingo Reporting System</title>
<body>
<h1>
<center>
<h1>Bingo Reporting System</h1>

<HR WIDTH=“80%”>
<h2>
<?php
require ‘bingodatabase.php’;

$sql = “select * from control where ID = ‘A’”;

$query = mysql_query($sql);
?>
<CENTER>
<?php

while ($row = mysql_fetch_array($query)) {

echo $row[‘OrganizationName’];
$d6 = $row[6];
$d9 = $row[7];
$d12 = $row[8];
$d15 = $row[9];
$d18 = $row[10];
$d24 = $row[11];
$d30 = $row[12];
$d36 = $row[13];
$n1 = $row[14];
$n2 = $row[15];
$n3 = $row[16];
$n4 = $row[17];
$n5 = $row[18];
$n6 = $row[19];
$n7 = $row[20];
$n8 = $row[21];
$n9 = $row[22];
$n10 = $row[23];
$n11 = $row[24];
$n12 = $row[25];
$n13 = $row[26];
$n14 = $row[27];
$n15 = $row[28];
}
$game = $_POST[‘submit’];

?>
<hr width=“80%”>

<form action = “bingosavegamechanges.php” method=“POST”>
<table><tr><td> </td><td>* BINGO *</td></tr>

 &lt;tr&gt;&lt;td&gt;Game Date&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="gamedate"
          value="yyyy-mm-dd"&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Early Bird&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="earlybird" 
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;50/50&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="5050" 
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="6"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="9"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="12"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="15"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;18&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="18"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;24&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="24"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;30&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="30"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;36&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="36"
          value=""&gt;&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Intermission 50/50&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="i5050"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Winner Take All&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="wta"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Miscellaneous&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="misc"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total Taken In&lt;/td&gt;&lt;td&gt;
         &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total Paid Out&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="bpaidout"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Profit&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Cash On Hand&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="bcoh"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;             
 &lt;tr&gt;&lt;td&gt;Checks used From&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="ckfrom"
          value=""&gt;&lt;/td&gt;&lt;td&gt;To&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="ckto"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Deposit&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="deposit"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;* TEARCARD *&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Cash On Hand&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="tcoh"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total Paid Out&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="tpo"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total COH/PO&lt;/td&gt;&lt;td&gt;
         &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Less Starting Cash&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="tstcash"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total Sold&lt;/td&gt;&lt;td&gt;
         &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Minus PO&lt;/td&gt;&lt;td&gt;
         &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Total Profit&lt;/td&gt;&lt;td&gt;
         &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Workers&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w1"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w2"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w3"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w4"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w5"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w6"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w7"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w8"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w9"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     
 &lt;tr&gt;&lt;td&gt;&nbsp;&lt;/td&gt;&lt;td&gt;
         &lt;input type="text" name="w10"
          value=""&gt;&lt;/td&gt;&lt;/tr&gt;     

</table>
<button type=“submit” name=“submit” value=“addnew”>Add Game Data</button>
<button type=“submit” name=“submit” value=“abort”>Abort Changes</button>

</form>
<hr width=“80%”>
<h6>
<form action=“bingoindex.php” method=“POST”>
<button type=“submit” name=“submit” value=“submit”>
(c) Copyright 2009 RDG Computer Services, 46 High Street,
Newport ME 04953 – All Rights Reserved
</button>
</form>
</h6>
</center>
<?php
mysql_close($dbh);
?>
</body>
</html>

I don’t understand what’s different between the Windows and Linux installations, but hope someone knows why this happens.

How do I set the error reporting to prevent this error from appearing?

Sounds like either php is not set up correctly to talk to Mysql in this way ( using native mysql_* functions) OR your database did not start up.

Compare your php_info() dumps very carefully around the Mysql function loads.

Else, var_dump( $query );

Else, make sure the database has the expected data in it AND that this user has permission to use the database.

Edit:

corblimey, ITMA, I’m off to watch #topgear - new season!

Your error reporting is different on the 2 hosts, the notices appear becuase you’re trying to access data in the $row array where no data exists.

Hence, Undefined Offset. :wink:

Clicking either has the expected result in Linux, but in Windows it acts as if “Abort Changes” was clicked no matter which is clicked. The code used for this is:

That would appear to be a html problem - you are using buttons to submit instead of submit inputs, its ok to do that but you have to be very sure about one instruction wiping out another and (usually) how any JS validation is structured, as well as browser differences.

Try changing them to:

<input type=“submit”>

and search SP for the term “two submit buttons one form” or similar.