Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP 5.2.8 Array issue 1

Status
Not open for further replies.

aalmeida

MIS
Aug 31, 2000
468
US
This is really odd and it seems to affect the Win32 version of PHP5.2.8 running on Windows 2003 and IIS6.
Code:
require_once('Connections/MySQLDb.php');
if (!isset($_SESSION)) {
  session_start();
  session_register($_compname);
  session_register($_compID);
  }
 
$MM_Company_rs_company = "/viva-verde/index2.php";
if (isset($_SERVER['HTTP_HOST'])) {
  $MM_Company_rs_company = $_SERVER['HTTP_HOST'];
}
mysql_select_db($database_ajmedia, $ajmedia);
$query_rs_company = sprintf("SELECT tbl_company.Comp_ID, tbl_company.Comp_Name FROM tbl_company WHERE tbl_company.Comp_URL = %s", GetSQLValueString($MM_Company_rs_company, "text"));
$rs_company = mysql_query($query_rs_company, $ajmedia) or die(mysql_error());
$row_rs_company = mysql_fetch_assoc($rs_company);
$totalRows_rs_company = mysql_num_rows($rs_company);

var_dump($row_rs_company);
  $_SESSION[$_compID] = $row_rs_company['Comp_ID'];
  $_SESSION[$_compname] = $row_rs_company['Comp_Name'];
echo '<br /> session Variables on Index2.php and $_SESSION[$_compID]='. $_SESSION[$_compID] .', $_SESSION[$_compname]=' . $_SESSION[$_compname].'.'


The var_dump($row_rs_company) returns:
array(2) { ["Comp_ID"]=> string(1) "6" ["Comp_Name"]=> string(18) "Viva Verde Imoveis" }

But the echo returns:
session Variables on Index2.php and $_SESSION[$_compID]=Viva Verde Imoveis, $_SESSION[$_compname]=Viva Verde Imoveis.
When it should be:
session Variables on Index2.php and $_SESSION[$_compID]="6", $_SESSION[$_compname]=Viva Verde Imoveis.

How can I fix this?


AL Almeida
CIO
May all those that come behind us, find us faithful
 
Code:
session_register($_compname);
this syntax is deprecated (as of 5.3) and has been disavowed for longer. please read up on sessions in the php manual. you should now be using $_SESSION['keyname'] = 'value';

don't use this
Code:
!isset($_SESSION

instead use this as per the manual
Code:
if (session_id()=='')

however your problem is simply that you have used a variable as a key in your $_SESSION assignments but have failed to declare the variable. as it is undeclared (in each case), php is inferring a null value. so you are, in fact, assigning the value each time to a key of $_SESSION[0]

i suspect that you want to be using string based keys, rather than variable based keys

Code:
$_SESSION[[red]'[/red]_compID[red]'[/red]]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top