Hi
My following php code keeps giving me Undefined Offset errors:
The code is:

<table border="1">
<tr>
<th>Tile </th> <th> Email</th> <th> Publication No. </th> <th> Submitted By: First Name </th> <th> Submitted By: Last Name </th> <th> File Name </th>
</tr>
<tr>
<?php
if(!($lines=file('publication.txt')))
{echo 'Error:Unable to open file!</body> </html>';exit;}
foreach($lines as $theline)
/*Line 134
*/
{list($title, $author, $pubno, $firstname, $lastname, $newname) = split '\|',$theline);
echo"
<tr>
<td>$title</td> <td>$author</td> <td>$pubno</td> <td>$firstname</td> <td>$lastname</td> <td>$newname</td </tr>";}?>
</table>

I keep getting the following errors:
Notice: Undefined offset: 5 to Undefined offset:1 on line 134

= split ('\|',$theline);

i must admit it is strange, but that missing bracket is still in the code- and it is still not working............

ya, that was just the first problem that I saw.

Undefined offset usually refers to the integer key of a numeric array.

without having a sample file to open and run it on, hard for me to determine where. got a small sample set for publication.txt?

First of all, those are notices and not errors. Notices are those which you can totally ignore. If you don't initialize the variables and use it, you will get a 'notice'. If you want to be a good programmer, initialize every variable you use to its respective default value.
"" for a string variable, 0 for an integer variable and so on.
If you are on a local system and have access to php.ini, you can avoid notices by changing error_reporting value.
Set it to error_reporting = E_ALL & ~E_NOTICE to get all errors except notices.

Try making this your code:

/*Line 134
*/
{ echo '<tr>'
foreach (explode('|',$theline) AS $val) {
  echo '<td>'.$val.'</td> ';
  }
echo '</tr>'; } ?>
</table>

Hi Thanks all, I know the problem now as the variables were not declared and it was just a notice rather than an error...but thanks all...it it works...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.