I had my server upgraded to php 5.2 and included error messages for debugging. Not a good thing - as they are all over the place with scripts that have been in place for years.

So, I need some help knowing how things need to be written differently in php 5.2 that are no longer valid from earlier versions of 4.

For example, I get this notice: Notice: Undefined index: submit in /var/www/vhosts/domain/httpdocs/Directory/form.php on line 270

line 270 reads:  if ($_POST == "Submit Search") {
list_matches ("42directory");
}

What need to change here?

Also, after submitting a form that inputs to a database, I get this notice:

Notice: Array to string conversion in /var/www/vhosts/domain/httpdocs/Directory/search.inc.php on line 23

That line is part of a clean array function:

function clean_array ($array, $remove='submit') {
//  global $remove;
$remove = array ('submit' => '');


if (is_array ($array)) {
$array = array_filter ($array, "strlen");
$array = array_filter ($array, "addslashes");
while (list ($key, $val) = each ($array)) {
if (!trim_array ($key, $remove)) {
$clean_array[$key] = $val;
}
}
return $clean_array;
} else {
return 0;
}
}

What is wrong with this one?

I know these are just notices, not errors, but it would be nice to clean all this up, and leanr a little more about php 5 in the process.

Rick

Make sure you go over to http://www.php.net/releases/ and check the changelogs for compatibility and major upgrades that can break code. Checking changelogs is always good practice when making an upgrade to prevent things like this.

Thanks - I planned on going over to php.net to see if there was a guide for what gets changed when these versions are upgraded.

It would still help if someone can guide me on these two issues.

Rick

Well both errors are pretty helpful since they explain in plain English exactly what is going wrong.
The first

Notice: Undefined index: submit in /var/www/vhosts/domain/httpdocs/Directory/form.php on line 270

Tells you that there is an Undefined index. In this line

if ($_POST['submit'] == "Submit Search") {

The 'submit' is called an index as it is an index to the location in the array. So what the notice is saying that there is nothing defined in the 'submit' position in the $_POST array.

For the second could you show the definition of your trim_array function because it isn't a built in PHP function unless it's new to 5.2

Okay - thanks on the first response, although I am not sure why it worked before, if there is nothing defined in the submit position, what did it do before the upgrade?

The function is not new to php 5, it was written a number of years ago by a friend of mine in Latvia. He is now doing IT in Sweden, and works for a school that gives him no time to freelance.

His description of it is:

Adds slashes and filters out entries that
don't have values, plus deletes values you
don't want to update against database fields.
Returns array with elements that have values and fileds
as counterparts in the database.Submit button entry.

It works because it's not an error since PHP is capable of implicit initialization meaning a variable is declared as soon as you use it if it was not declared before as opposed to C or C++ which requires explicit initialization.
Aside from that I meant the actual code for the function, the description of it doesn't really help when debugging it :)

Okay - I thought I had included the code in the first posting:

function clean_array ($array, $remove='submit') {
//  global $remove;
$remove = array ('submit' => '');


if (is_array ($array)) {
$array = array_filter ($array, "strlen");
$array = array_filter ($array, "addslashes");
while (list ($key, $val) = each ($array)) {
if (!trim_array ($key, $remove)) {
$clean_array[$key] = $val;
}
}
return $clean_array;
} else {
return 0;
}
}

I'm not sure what more you are asking for.

Thanks for your quick responses!

No, the code for the trim_array function, not for clean_array

Oh - sorry.

It is:

function trim_array ($key, $arr) {
    foreach (array_keys($arr) as $k)
        if ($k == $key)
            return true;
    return false;
}
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.