Undefined offset: 1 using list() and split()

A few times, I have gotten "Undefined offset: 1" and I can't figure out why it is happening.  Most of the time nothing happens.

Below is the code snippet


$selByReport = @$_POST['selByReport'];
 
if ($selByReport != ""   && strtoupper(substr($selByReport,0,6)) != "SELECT")
{
     list($ReportName,$ReportRevision) = split('-',$selByReport);
}

Open in new window

taylort2Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hernst42Connect With a Mentor Commented:
$_POST['selByReport'] might not be empty, it might just contain something invalid like 1221 or a ,b, ..
The attached code should give you an error if the - is missing
<?php
$selByReport = @$_POST['selByReport'];
if ($selByReport != ""   && strtoupper(substr($selByReport,0,6)) != "SELECT")
{
    if (strpos($selByReport, '-') == false) {
        echo "`$selByReport` has an invalid format";
    } else {
        list($ReportName,$ReportRevision) = split('-',$selByReport);
    }
}

Open in new window

0
 
hernst42Commented:
You get that error if there is no - in $_POST['selByReport']
0
 
taylort2Author Commented:
The $_POST['selByReport'] is currently blank so the code should not be executing at all.  My if-statement should be stopping the code from running but once in a great while it doesn't.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ArikaelCommented:
Could it be a HTML error (like a missed bracket) in your html-form which results in sending junk data.

What does
print_r($_POST);
display?
0
 
taylort2Author Commented:
Arikael,

The data being submitted is correct(no junk).  It's that this error has only occurred once or twice since the page has been up.

hernst42,

I was adding the extra check when I notice your code.


Thanks guys.

0
 
taylort2Author Commented:
I usually put extra checks in my code but lately I have been required to finish ASAP then move on to the next project.  Thanks.
0
All Courses

From novice to tech pro — start learning today.