PHP code no longer works - diff btwn PHP4 and PHP5?

I have a hosting site on a GoDaddy server - using the same php code and same tab-delimited data files. Godaddy no longer supports php4 - and my code no longer works. If some body could take a look and suggest what I might be doing wrong I’d be very appreciative!

The error I’m getting is “Warning: Invalid argument supplied for foreach() in /home/content/n/i/b/nibrs/html/cgi/property.php on line 43”

Code follows:

[code]

Crime Reporting Unit Property Report

Note: The Following table is a property stolen, with the data converted from NIBRS cases reported by this agency for the year in question.

<?php

$filename = “/home/content/n/i/b/nibrs/html/datafiles/prop.dat”; //here’s the filename

$id = fopen($filename, “r”); //open the file
while ($data = fgetcsv($id, filesize($filename),"\t")) //start a loop

echo “
$data[0]\n”;

if ($data[1] == “$ori” and $data[2] == “$year”)
$table[] = $data; //put each line into its own entry in the $table array
fclose($id); //close file

echo “

\n”;
echo “<td align='center’rowspan=‘2’>ORI<td align='center’rowspan=‘2’>Year<td align='center’rowspan=‘2’>Month<td align='center’colspan=‘7’>Robbery by Location<td align='center’colspan=‘2’>Burglary by Location<td align='center’colspan=‘3’>Larceny by Value<td align='center’colspan=‘9’>Nature of Larceny\n”;
echo "\n"; foreach($table as $row)

{
echo “

”;
foreach($row as $data)
echo “<td align='center’align=‘right’>$data”;
echo “\n”;
}

echo “

AgencyMonths
Hiway Comm. House Gas Station Conv. Store Residence Bank Misc Residence Non- Residence $200 and Over $50 - $200 Under $50 Pocket- picking Purse Snatching Shop lifting From Motor Veh MV Parts/Access Bicycle From Building Coin- op All Other Reporting
\n”;

?>

[/code]

Thanks!

Dan B

Is the file path still correct and got all the right data in it?

Yes it does! To test that out, I removed the ‘#’ from this line: # echo “
$data[0]\n”; and ran it - and got all 500o+ lines of data (well, the first item in the lines of data).

But thanks for the response - any other suggestions???

Ahh, i reckon it’s because you haven’t initialised the $table variable.

[php]$id = fopen($filename, “r”); //open the file
$table = array();
while ($data = fgetcsv($id, filesize($filename),"\t")) //start a loop

echo “
$data[0]\n”;

if ($data[1] == “$ori” and $data[2] == “$year”)
$table[] = $data; //put each line into its own entry in the $table array
fclose($id); //close file[/php]

Thanks for the hint - I think there is a more basic problem in the code.
Here’s the situation - the user is shown a web page with a form in it:

Agency:
Year: 2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010

But if I comment out the line "if ($data[1] == "$ori… the php will show all the lines of data - so I think the ‘ori’ and ‘year’ values are not being sent from the html into the php.

Is there a way I can check to see if the ‘select’ values in the form are being sent to the php???

on the PHP file that you will process that value, echo to see if it contains the selected value
[php]
print_r($_REQUEST[‘year’]);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service