Page 1 of 1

PHP5 upgrading issue

Posted: Sun Aug 10, 2008 11:53 am
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

Re: PHP5 upgrading issue

Posted: Sun Aug 10, 2008 12:40 pm
by Christopher
Either turn off notices, or better would be something like:

Code: Select all

$river = isset($_REQUEST['river']) ? $_REQUEST['river'] : '';

Re: PHP5 upgrading issue

Posted: Sun Aug 10, 2008 1:44 pm
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

Re: PHP5 upgrading issue

Posted: Sun Aug 10, 2008 1:56 pm
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

Re: PHP5 upgrading issue

Posted: Sun Aug 10, 2008 8:46 pm
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'.