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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
hernst42Commented:
$_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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.