FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Undefined variable: Origin
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Undefined variable: Origin [message #174250 is a reply to message #174249] Sat, 28 May 2011 12:56 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma:
Senior Member
On 28-05-2011 14:42, Co wrote:
> On 28 mei, 14:37, Luuk <L...@invalid.lan> wrote:
>> On 28-05-2011 14:22, Co wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On 28 mei, 14:08, Luuk <L...@invalid.lan> wrote:
>>>> On 28-05-2011 14:03, Co wrote:
>>
>>>> > On 28 mei, 11:57, Luuk <L...@invalid.lan> wrote:
>>>> >> On 28-05-2011 11:41, Co wrote:
>>
>>>> >>> On 28 mei, 11:34, Luuk <L...@invalid.lan> wrote:
>>>> >>>> On 28-05-2011 11:30, Co wrote:
>>
>>>> >>>>> On 28 mei, 11:17, Luuk <L...@invalid.lan> wrote:
>>>> >>>>>> On 28-05-2011 08:51, Co wrote:
>>
>>>> >>>>>>> Hi All,
>>
>>>> >>>>>>> I give two values from one php page to the next.
>>>> >>>>>>> <a href="MembersFrom.php?myCountry=Netherlands&myFlag=nl.gif">
>>
>>>> >>>>>>> On the second page I first define them:
>>>> >>>>>>> if (isset($_GET['myCountry'])) {
>>>> >>>>>>> $Origin = $_GET['myCountry'];
>>>> >>>>>>> $Flag = $_GET['myFlag'];
>>>> >>>>>>> }
>>
>>>> >>>>>>> $queryString = "WHERE email_activated='1' AND country='$Origin' AND
>>>> >>>>>>> active='1' ORDER BY id ASC";
>>>> >>>>>>> $sql2 = mysql_query("SELECT * FROM myMembers $queryString $limit") ;
>>
>>>> >>>>>>> I limit the data to one record per page.
>>>> >>>>>>> However when I want to go to the next record on a new page he doesn't
>>>> >>>>>>> recognize the variable Origin anymore in here:
>>>> >>>>>>> $queryString = "WHERE email_activated='1' AND country='$Origin' AND
>>>> >>>>>>> active='1' ORDER BY id ASC";
>>
>>>> >>>>>>> How should I save the value in Origin so it can be used everytime
>>>> >>>>>>> again?
>>
>>>> >>>>>>> Marco
>>
>>>> >>>>>> You will need a session
>>
>>>> >>>>>> http://nl2.php.net/manual/en/function.session-start.php
>>
>>>> >>>>>> --
>>>> >>>>>> Luuk
>>
>>>> >>>>> Can you have more than one sessions?
>>>> >>>>> Could you give me some example of start and end of this session?
>>
>>>> >>>>> Marco
>>
>>>> >>>> What is wrong with the examples at the given page?
>>
>>>> >>>> --
>>>> >>>> Luuk
>>>> >>> I put in this code:
>>
>>>> >>> session_start();
>>>> >>> $_SESSION['Origin'] = $_GET['myCountry'];
>>>> >>> $_SESSION['Flag'] = $_GET['myFlag'];
>>
>>>> >>> //if (isset($_GET['myCountry'])) {
>>>> >>> // $Origin = $_GET['myCountry'];
>>>> >>> // $Flag = $_GET['myFlag'];
>>>> >>> //}
>>>> >>> $queryString = "WHERE email_activated='1' AND country='$Origin' AND
>>>> >>> active='1' ORDER BY id ASC";
>>
>>>> >>> How can I give the $_SESSION['Origin'] to the query?
>>>> >>> Marco
>>
>>>> >> try this:
>>>> >> session_start();
>>>> >> print "Session Origin: ".$_SESSION['Origin']."<br>";
>>>> >> $_SESSION['Origin'] = $_GET['myCountry'];
>>>> >> print "Session Origin replaced with value from _GET:
>>>> >> ".$_SESSION['Origin']."<br>";
>>>> >> $_SESSION['Flag'] = $_GET['myFlag'];
>>
>>>> >> The first time you start this page $_SESSION['Origin'] will be empty
>>
>>>> >> The second time it will hold the value of the previous $_GET['myCountry']
>>
>>>> >> In other words,
>>
>>>> >> If $_GET['myCountry'] is empty, you should not do:
>>>> >> $_SESSION['Origin'] = $_GET['myCountry'];
>>
>>>> >> --
>>>> >> Luuk
>>
>>>> > When I try your code and go to the second page I get three
>>>> > notifications:
>>
>>>> > Notice: A session had already been started - ignoring session_start()
>>>> > Notice: Undefined index: myCountry
>>>> > Notice: Undefined index: myFlag
>>
>>>> > on these lines:
>>>> > $_SESSION['Origin'] = $_GET['myCountry'];
>>>> > $_SESSION['Flag'] = $_GET['myFlag'];
>>
>>>> so, *why* do tou do this (quoted from your original post)
>>
>>>> if (isset($_GET['myCountry'])) {
>>>> $Origin = $_GET['myCountry'];
>>>> $Flag = $_GET['myFlag'];
>>
>>>> }
>>
>>>> Question: Do you want to learn programming, or just want to learn how to
>>>> copy/paste ?
>>
>>>> --
>>>> Luuk
>>
>>> I did that because i got the warning for unidentified variable.
>>> Of course I want to learn how to program but what use is it if it
>>> doesn't work.
>>
>>> The point is that I have to take to variables from my main page.
>>> Country and flag.
>>> MembersFrom.php?myCountry=Netherlands&myFlag=nl.gif
>>> In the record form I want to show all members from Country X and show
>>> their flag Y.
>>> This works with what I used in the beginning. However if I go to the
>>> next record (next page)
>>> the values get lost.
>>> So I need to store the values somewhere if I load :
>>> MembersFrom.php?pn=2
>>
>>> Marco
>>
>> That was your question in the first place
>>
>> i answered that you could use sessions to do that
>>
>> in your first page 'MembersFrom.php' you store 'myCountry' in a session
>> variable:
>> $_SESSION['Origin'] = $_GET['myCountry'];
>>
>> and in you second page, after the session started, you can acces the
>> values again via the variable $_SESSION['Origin']
>>
>> session_start();
>> if (isset($_GET['myCountry'])) {
>> // Get values if they are defined in the URL
>> $Origin = $_GET['myCountry'];
>> // and store them in the session
>> $_SESSION['Origin'] = $Origin;} else {
>>
>> // Get the value from the session
>> $Origin = $_SESSION['Origin'];
>>
>> }
>>
>> --
>> Luuk
>
> Luuk,
>
> I do understand that but it still gives me this warning that a session
> has already started.
> A session starts when I open the index.php and the checkusrlog.php is
> run.
>
> Marco

My crystal ball is not clear about how 'index.php', 'MembersFrom.php'
and 'checkusrlog.php' relatie to each other.....

You only need to start a session once (per page that is requested)

If you include other php-scripts in one page, than you should not try to
start a session from those included pages, if a session is already
started from the main page...


--
Luuk
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Persistence engine for GWT
Next Topic: input country name and query database to output google map
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 01:23:48 GMT 2024

Total time taken to generate the page: 0.04194 seconds