PHP5 upgrading issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steduf
Forum Newbie
Posts: 2
Joined: Sun Aug 10, 2008 11:45 am

PHP5 upgrading issue

Post by steduf »

Hi

I wrote a php website a few years ago using php4, the host has now upgraded to php5 and im getting a few errors.

The one i cant resolve is...

Notice: Undefined index: river in

on the line... $river = $_REQUEST['river'];

I think river is coming from... <select id="river" name="river" tabindex="15">

The code still works but im getting an error on the screen

Any help would be very much appreiated.

Many Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP5 upgrading issue

Post by Christopher »

Either turn off notices, or better would be something like:

Code: Select all

$river = isset($_REQUEST['river']) ? $_REQUEST['river'] : '';
(#10850)
steduf
Forum Newbie
Posts: 2
Joined: Sun Aug 10, 2008 11:45 am

Re: PHP5 upgrading issue

Post by steduf »

Thanks Christopher

Im now getting the error...
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5

The lines are...
$getRiverId = mysql_query("SELECT River_id FROM tblRivers WHERE River_name = '$river'");
$id = mysql_result($getRiverId,0,0);

Im getting the error on the second line

Any ideas

Thanks again
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: PHP5 upgrading issue

Post by desmi »

Try to get the id like this:

Code: Select all

 
 
$getRiverId = mysql_query("SELECT * FROM tblRivers WHERE River_name = '$river'");
$result = mysql_fetch_array($getRiverId);
 
$id = $result['River_id'];
 
 
 
Might be just a newbie advise but.. Worth a try.. ;P
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP5 upgrading issue

Post by RobertGonzalez »

You are making an assumption with your code that the REQUEST var 'river' is always set. That is why you are now getting errors. The code arborint posted checks to see if it is set and if it is grabs it, otherwise it sets $river to an empty string. When you push that empty string to your query the result set is coming back empty, null or void which is why you are having problems walking your way through it.

I would put the query inside a conditional check for the var you are expecting ('river' in this case) then, if 'river' is set, handle the query, otherwise notify the user that they need to select something for 'river'.
Post Reply