Author Topic: PHP code no longer works - diff btwn PHP4 and PHP5?  (Read 368 times)

danno02052

  • New Member
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
PHP code no longer works - diff btwn PHP4 and PHP5?
« on: August 16, 2012, 01:10:11 PM »
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: [Select]
<html>
<body>
    <TITLE>
        Crime Reporting Unit Property Report
    </TITLE>
</HEAD>
   <BODY>
<h2>Note:  The Following table is a property stolen, with the data converted from NIBRS cases reported by this agency for the year in question.  </h2>
<?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($idfilesize($filename),"\t")) //start a loop
# echo "<br>$data[0]\n";
if ($data[1] == "$oriand $data[2] == "$year")
$table[] = $data//put each line into its own entry in the $table array
fclose($id); //close file

echo "<table border='1'>\n";
echo 
"<tr><td align='center' rowspan='2'>Agency</td><td align='center'rowspan='2'>ORI</td><td align='center'rowspan='2'>Year</td><td align='center'rowspan='2'>Month</td><td align='center'colspan='7'>Robbery by Location</td><td align='center'colspan='2'>Burglary by Location</td><td align='center'colspan='3'>Larceny by Value</td><td align='center'colspan='9'>Nature of Larceny</td><td>Months</td></tr>\n";
echo 
"<tr><td>Hiway</td><td>Comm. House</td><td>Gas Station</td><td>Conv. Store</td><td>Residence</td><td>Bank</td><td>Misc</td><td>Residence</td><td>Non- Residence</td><td>$200 and Over</td><td>$50 - $200</td><td>Under $50</td>
 <td>Pocket- picking</td><td>Purse Snatching</td><td>Shop lifting</td><td>From Motor Veh</td><td>MV Parts/Access</td><td>Bicycle</td><td>From Building</td><td>Coin- op</td><td>All Other</td><td>Reporting</td></tr>\n"
;
foreach(
$table as $row)

{
echo 
"<tr>";
  foreach(
$row as $data)
  echo 
"<td align='center'align='right'>$data</td>";
echo 
"</tr>\n";
}

echo 
"</table>\n";

?>

</body>
</html>

Thanks!

Dan B

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 618
  • Karma: 9
    • View Profile
Re: PHP code no longer works - diff btwn PHP4 and PHP5?
« Reply #1 on: August 16, 2012, 04:48:26 PM »
Is the file path still correct and got all the right data in it?

danno02052

  • New Member
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: PHP code no longer works - diff btwn PHP4 and PHP5?
« Reply #2 on: August 16, 2012, 05:32:44 PM »
Yes it does! To test that out, I removed the '#' from this line: # echo "<br>$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???

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 618
  • Karma: 9
    • View Profile
Re: PHP code no longer works - diff btwn PHP4 and PHP5?
« Reply #3 on: August 17, 2012, 06:30:10 AM »
Ahh, i reckon it's because you haven't initialised the $table variable.

PHP Code: [Select]
$id fopen($filename"r"); //open the file
$table = array();
while (
$data fgetcsv($idfilesize($filename),"\t")) //start a loop
# echo "<br>$data[0]\n";
if ($data[1] == "$oriand $data[2] == "$year")
$table[] = $data//put each line into its own entry in the $table array
fclose($id); //close file

danno02052

  • New Member
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: PHP code no longer works - diff btwn PHP4 and PHP5?
« Reply #4 on: August 17, 2012, 07:44:01 AM »
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:

<FORM ACTION="cgi/ytd.php" METHOD="POST"><table>
<tr valign=top><td>Agency:</td><td><select name="ori">
<!--#include file="agencylist.txt" -->
<tr valign=top><td>Year:</td><td><select name="year">
<option value="2000"> 2000<BR>
<option value="2001"> 2001<BR>
<option value="2002"> 2002<BR>
<option value="2003"> 2003<BR>
<option value="2004"> 2004<BR>
<option value="2005"> 2005<BR>
<option value="2006"> 2006<BR>
<option value="2007"> 2007<BR>
<option value="2008"> 2008<BR>
<option value="2009"> 2009<BR>
<option value="2010"> 2010<BR>
</td></tr>
</table><input type=submit></form>

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


wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: PHP code no longer works - diff btwn PHP4 and PHP5?
« Reply #5 on: August 17, 2012, 04:45:51 PM »
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 Code: [Select]

print_r
($_REQUEST['year']);
If help you, Click the [+] Karma to thanks me