Undefined Index error in $_REQUEST
Moderator: General Moderators
-
waqas_punjabian
- Forum Commoner
- Posts: 67
- Joined: Wed Aug 10, 2005 9:53 am
Undefined Index error in $_REQUEST
Hi gals n guys,,,
i m facing two strange errors in all variables and all pages , but i 'll ask about one page and if this problem will be solved here than i 'll be able to solve it in all pages .
the"findbooks.php" there i 've used
$var_ac = $_request[action];
and i m getting two errors while executing this file on local server i.e) IIS ...
First error is :
Notice: Use of undefined constant action - assumed 'action' in D:\projects\Got_Med_Books\theSite\www\findbooks.php on line 6
and Secound error is :
Notice: Undefined index: action in D:\projects\Got_Med_Books\theSite\www\findbooks.php on line 6
and the strange thing is when i uploaded this file to a live server, it worked perfiectly. there were not both of the errors ...
Wht the reason could be ???
Further more, i ve tried following things to make this error to be solved, but it did'nt work :
First : i 've tried to give it qouts like $var_ac = $_request['action']
then first error 've been solved ...
( but it will be too much time consuming to change in all vars and files)
Second : i 've tried to make some change in "php.ini" i.e)
register_globals = on
but it also did'nt work ...
plzz ,,, help me to work with these files at local server otherwise it would be terible to upload each file and test it on internet .
Thanks in ADVANCE
regards
Waqas
i m facing two strange errors in all variables and all pages , but i 'll ask about one page and if this problem will be solved here than i 'll be able to solve it in all pages .
the"findbooks.php" there i 've used
$var_ac = $_request[action];
and i m getting two errors while executing this file on local server i.e) IIS ...
First error is :
Notice: Use of undefined constant action - assumed 'action' in D:\projects\Got_Med_Books\theSite\www\findbooks.php on line 6
and Secound error is :
Notice: Undefined index: action in D:\projects\Got_Med_Books\theSite\www\findbooks.php on line 6
and the strange thing is when i uploaded this file to a live server, it worked perfiectly. there were not both of the errors ...
Wht the reason could be ???
Further more, i ve tried following things to make this error to be solved, but it did'nt work :
First : i 've tried to give it qouts like $var_ac = $_request['action']
then first error 've been solved ...
( but it will be too much time consuming to change in all vars and files)
Second : i 've tried to make some change in "php.ini" i.e)
register_globals = on
but it also did'nt work ...
plzz ,,, help me to work with these files at local server otherwise it would be terible to upload each file and test it on internet .
Thanks in ADVANCE
regards
Waqas
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
register_globals should be off.
the first "error" is from using action versus 'action' when you didn't have a constant defined as action. That's pretty straight forward to fix.
Your second "error" is because the element doesn't exist in the array you specified. Using isset() to check if the element exists before using it is always a good idea.
Do not take the band-aid approach and just turn off notices.
the first "error" is from using action versus 'action' when you didn't have a constant defined as action. That's pretty straight forward to fix.
Your second "error" is because the element doesn't exist in the array you specified. Using isset() to check if the element exists before using it is always a good idea.
Do not take the band-aid approach and just turn off notices.
-
waqas_punjabian
- Forum Commoner
- Posts: 67
- Joined: Wed Aug 10, 2005 9:53 am
y same code is working at internet ???
But sir , the thing is, y the same code is working perfectly at online server. (at internet) ? if it is working there then may be i 'll be able to make it workable here ....
maybe i 'll have to make any change .... kindly tell me if u 've some idea ?
Take care
Bye
maybe i 'll have to make any change .... kindly tell me if u 've some idea ?
Take care
Bye
Re: y same code is working at internet ???
Its not working perfectly. The online server just turned off notices, so you dont SEE the notices that something is wrong.waqas@balianti.com wrote:But sir , the thing is, y the same code is working perfectly at online server. (at internet) ?
He explained how to fix it correctly.waqas@balianti.com wrote:if it is working there then may be i 'll be able to make it workable here ....
-
waqas_punjabian
- Forum Commoner
- Posts: 67
- Joined: Wed Aug 10, 2005 9:53 am
How can i turn off the notices ???
Hi,
How can i turn off the notices ??? like at internet most of servers do it..
Bye
How can i turn off the notices ??? like at internet most of servers do it..
Bye
Re: How can i turn off the notices ???
The notices are saying "Something is wrong". You don't want to turn them off, because something is wrong.waqas@balianti.com wrote:How can i turn off the notices ??? like at internet most of servers do it..
Fix the something that is wrong. We've already explained how to.
-
waqas_punjabian
- Forum Commoner
- Posts: 67
- Joined: Wed Aug 10, 2005 9:53 am
hi
one thing more i want to ask ,
U said that i should check my variable array in isset() ,..., ok that's fine but i m confuse about a couple of things . at start of the page the code is written as follows :
$action = $_REQUEST[action];
But by default, for the first time, when this page will be opened, i don't want this variable to be functional , but at the second time when user will visit this page this variable should be active.and then on the base of this action variable things are going to be extracted from database, and obviously all other functionality is being perform.
Wht should i do in default case ,..., that i don't want to use this variable and it should not give error ?
and Sir, i found $_GET or $_POST is perfect at the same place at default while i did'nt set any default value for that, but $_REQUEST is a very bad approach .
(And i m amazed it's going on perfectly on internet)
Anyway, Thanks a lot for ur Replies
Bye
U said that i should check my variable array in isset() ,..., ok that's fine but i m confuse about a couple of things . at start of the page the code is written as follows :
$action = $_REQUEST[action];
But by default, for the first time, when this page will be opened, i don't want this variable to be functional , but at the second time when user will visit this page this variable should be active.and then on the base of this action variable things are going to be extracted from database, and obviously all other functionality is being perform.
Wht should i do in default case ,..., that i don't want to use this variable and it should not give error ?
and Sir, i found $_GET or $_POST is perfect at the same place at default while i did'nt set any default value for that, but $_REQUEST is a very bad approach .
(And i m amazed it's going on perfectly on internet)
Anyway, Thanks a lot for ur Replies
Bye
isset()
Hi,
The isset(); function will help you decide which case it is:
1.Otherwise, the page has not been displayed and the variable has NOT been set.
2.If the variable has a value in it, then it is set (page has been displayed the second time).
The isset(); function will help you decide which case it is:
1.Otherwise, the page has not been displayed and the variable has NOT been set.
2.If the variable has a value in it, then it is set (page has been displayed the second time).
Re: isset()
Not true! Both of the following return TRUE to isset() but have no value: $i = 0; $i = '';AnarKy wrote:2.If the variable has a value in it, then it is set .
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Oh, really?bokehman wrote:To avoid the 'notice' isset() is needed not !empty()feyd wrote:those are valid values for isset to know the variable has been set. You may want to look at empty()
Code: Select all
<?php
if(empty($iDontExist))
{
echo "I don't exist.";
}
else
{
echo "I exist.";
}
?>Code: Select all
I don't exist.empty() wrote:empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.
It looks like you are right. I though running if(empty($iDontExist)) would set the variable but on closer examination I have found it doesn't.
Last edited by bokehman on Fri Aug 12, 2005 9:06 am, edited 1 time in total.