Connecting Tech Pros Worldwide Help | Site Map

Please help me with isset Function

  #1  
Old July 17th, 2005, 02:09 AM
christian9997
Guest
 
Posts: n/a
Hi

I don't seem to understand the way isset works.

Here is some Javascript code that makes a call using PHP:

// USER CAME BACK TO CHANGE LANGUAGE
if (<?echo isset($_REQUEST["changeLanguage"])?>) {
alert("WORKS1");
desiredLanguage = "<?echo $_REQUEST["changeLanguage"]?>";
cookieIsSet = 2;
}

I am not passing any $_REQUEST["changeLanguage"] parameter!
Here is the resulting HTML page source:

// USER CAME BACK TO CHANGE LANGUAGE
if () {
alert("WORKS1");
desiredLanguage = "";
cookieIsSet = 2;
}

I thought isset should return false as it doesn't exist. Why is it
returning nothing?
Thank you for any help
  #2  
Old July 17th, 2005, 02:09 AM
Tom Thackrey
Guest
 
Posts: n/a

re: Please help me with isset Function



On 15-Nov-2003, christian9997@hotmail.com (christian9997) wrote:
[color=blue]
> I don't seem to understand the way isset works.
>
> Here is some Javascript code that makes a call using PHP:
>
> // USER CAME BACK TO CHANGE LANGUAGE
> if (<?echo isset($_REQUEST["changeLanguage"])?>) {
> alert("WORKS1");
> desiredLanguage = "<?echo $_REQUEST["changeLanguage"]?>";
> cookieIsSet = 2;
> }
>
> I am not passing any $_REQUEST["changeLanguage"] parameter!
> Here is the resulting HTML page source:
>
> // USER CAME BACK TO CHANGE LANGUAGE
> if () {
> alert("WORKS1");
> desiredLanguage = "";
> cookieIsSet = 2;
> }
>
> I thought isset should return false as it doesn't exist. Why is it
> returning nothing?[/color]

I guess it's returning null which is evaluates to false. You could add zero
to the result or use <? echo (isset(...))?'1':'0'; ?>

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
  #3  
Old July 17th, 2005, 02:09 AM
Alexander M. Turek
Guest
 
Posts: n/a

re: Please help me with isset Function


Hi,

Am 15 Nov 2003 08:44:47 -0800 hat christian9997
<christian9997@hotmail.com> geschrieben:
[color=blue]
>
> I thought isset should return false as it doesn't exist. Why is it
> returning nothing?
> Thank you for any help[/color]

isset() does return the boolean false, but echo needs a string, not a
boolean.
This is why php converts the boolean return value to a string, false
becomes "" (empty string).

btw, your JS does not make much sense: Why do you print an if expression
that will never be executed? Instead, you could include the JS code only
when it's needed.

--

Alexander M. Turek
<rabus@users.sourceforge.net>

The phpMyAdmin Project
<http://www.phpmyadmin.net>
  #4  
Old July 17th, 2005, 02:09 AM
Martin McNulty
Guest
 
Posts: n/a

re: Please help me with isset Function


Thank you to both of you for your answers they were very helpful.

"Alexander M. Turek" <alexander.turek@stud.uni-karlsruhe.de> schrieb im
Newsbeitrag news:opryovygt72mcye9@news.rz.uni-karlsruhe.de...[color=blue]
> btw, your JS does not make much sense: Why do you print an if expression
> that will never be executed? Instead, you could include the JS code only
> when it's needed.[/color]

At the moment I am working on a sort of prototype using mostly HTML and
Javascript and only PHP when I really need it (for requests and database
access). Once I get the website working I will try and refine the code using
PHP.
As this is my first PHP project I'm not really sure of the impact PHP has on
the server performance, thats why I'm doing most of the processing on the
client side. However your observation is totally right and I hadn't actually
thought of it ;-)
Thanks


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with Internet Explorer swethak answers 2 May 22nd, 2009 10:15 AM
PHP Functions, Calling function in another page. eragon answers 8 June 25th, 2007 11:11 PM
Variable Substitution Using Query String Params - PLEASE HELP Skip answers 3 February 12th, 2007 03:15 PM
Login Page: Remember ME Shakun answers 2 April 6th, 2006 01:35 PM