Page 1 of 1
Sessions Issue
Posted: Mon Nov 17, 2003 3:11 pm
by Saethyr
Have never used them, never been a need until now so I am curious why the following is not working
Code: Select all
<?php
session_start() //Top of every page
function getID($fname, $lname)
{
//Check for Session ID
if (!$PHPSESSID)
{
session_register("TechID")
}
else if (!$TechID)
{
session_register("TechID")
}
//Db Connection
$connection = mysql_connect ("localhost", $DbUsername, $DbPassword);
mysql_select_db ($DbName, $connection);
//SQL for inserting new Data
$sql = "SELECT TechID from techinfo where FName = '$fName' AND LName = '$lName'";
//Execute Query
mysql_query($sql);
//Assign Value to Session
while ($row = mysql_fetch_array($sql_result)) {
$_SESSION["TechID"] = $row["TechID"];
}
}
?>
I am calling this function from another page, whioch my functions page is included as well, but, I can pull the session ID by not $TechID. Any help would be appriciated.
Saethyr
Posted: Mon Nov 17, 2003 3:20 pm
by Paddy
session_start needs a semi colon after it.
session_start();
Posted: Mon Nov 17, 2003 3:23 pm
by Saethyr
yeah it's there, I just left it out on here because I typed it in, the rest is pasted.
Posted: Mon Nov 17, 2003 3:27 pm
by Paddy
Not sure if it is the answer but I always use single quotes here.
$_SESSION['TechID'] = $row['TechID'];
Posted: Mon Nov 17, 2003 3:28 pm
by JayBird
Think this should fix it mate
Code: Select all
<?php
session_start(); //Top of every page
function getID($fname, $lname)
{
//Check for Session ID
if (!$PHPSESSID)
{
session_register("TechID")
}
else if (!$TechID)
{
session_register("TechID")
}
//Db Connection
$connection = mysql_connect ("localhost", $DbUsername, $DbPassword);
mysql_select_db ($DbName, $connection);
//SQL for inserting new Data
$sql = "SELECT TechID from techinfo where FName = '$fName' AND LName = '$lName'";
//Execute Query
$sql_result = mysql_query($sql);
//Assign Value to Session
while ($row = mysql_fetch_array($sql_result)) {
$_SESSION["TechID"] = $row["TechID"];
}
}
?>
you haven't set $sql_result.
Mark
Posted: Mon Nov 17, 2003 3:30 pm
by Paddy
I should wake up before I start posting.

Posted: Mon Nov 17, 2003 3:32 pm
by JayBird
...and BTW, it doesn't matter if you use single or double quotes
Mark
Posted: Mon Nov 17, 2003 3:33 pm
by Saethyr
Hell Paddy I should wake up before I start coding I guess.
Thanks Bech I knew it would take another set of eyes
Saethyr
Posted: Mon Nov 17, 2003 4:13 pm
by Saethyr
Now to get the Session to carry yto another page is it just
Code: Select all
<?
session_start();
echo "$TechID"; //Is this the Way?
php
?>
Posted: Mon Nov 17, 2003 4:19 pm
by Paddy
$TechID = $_SESSION['TechID'];
echo $TechID;
Posted: Mon Nov 17, 2003 8:08 pm
by Saethyr
Thanks Paddy

Posted: Tue Nov 18, 2003 3:44 am
by twigletmac
Just a heads up, don't use session_register() and $_SESSION together - they don't play nice and you generally get fairly buggy results. In fact you shouldn't use session_register() at all (it's deprecated and doesn't work with register_globals off). In your function you can just delete:
Code: Select all
//Check for Session ID
if (!$PHPSESSID)
{
session_register("TechID")
}
else if (!$TechID)
{
session_register("TechID")
}
the following line:
Code: Select all
$_SESSION["TechID"] = $row["TechID"];
makes that code uneccessary.
Mac
Posted: Tue Nov 18, 2003 7:50 am
by Saethyr
Thanks Twig!
Still was not working last night so I will try this when I get home to see if I can make it work. coming from ASP sessions these are bit more difficult to make work it seems.
Saethyr