User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 375,198 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,994 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 225 | Replies: 8
Reply
Join Date: Apr 2008
Posts: 5
Reputation: raweiss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raweiss raweiss is offline Offline
Newbie Poster

errors since upgrade to php 5.2

  #1  
Apr 22nd, 2008
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'] == "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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 442
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 65
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: errors since upgrade to php 5.2

  #2  
Apr 22nd, 2008
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.
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Apr 2008
Posts: 5
Reputation: raweiss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raweiss raweiss is offline Offline
Newbie Poster

Re: errors since upgrade to php 5.2

  #3  
Apr 22nd, 2008
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
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 442
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 65
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: errors since upgrade to php 5.2

  #4  
Apr 22nd, 2008
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
  1. 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
Last edited by ShawnCplus : Apr 22nd, 2008 at 2:02 pm.
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Apr 2008
Posts: 5
Reputation: raweiss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raweiss raweiss is offline Offline
Newbie Poster

Re: errors since upgrade to php 5.2

  #5  
Apr 22nd, 2008
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.
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 442
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 65
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: errors since upgrade to php 5.2

  #6  
Apr 22nd, 2008
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
Last edited by ShawnCplus : Apr 22nd, 2008 at 2:19 pm.
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Apr 2008
Posts: 5
Reputation: raweiss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raweiss raweiss is offline Offline
Newbie Poster

Re: errors since upgrade to php 5.2

  #7  
Apr 22nd, 2008
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!
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 442
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 65
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: errors since upgrade to php 5.2

  #8  
Apr 22nd, 2008
No, the code for the trim_array function, not for clean_array
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Apr 2008
Posts: 5
Reputation: raweiss is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raweiss raweiss is offline Offline
Newbie Poster

Re: errors since upgrade to php 5.2

  #9  
Apr 22nd, 2008
Oh - sorry.

It is: function trim_array ($key, $arr) {
foreach (array_keys($arr) as $k)
if ($k == $key)
return true;
return false;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC