Forum Moderators: coopster

Message Too Old, No Replies

Need understanding why losing a $value

I have no clue why

         

henry0

1:10 pm on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As is it does the job but I do not like it that way!
here is the story: this is part of an already too long script (700+)
in addition the are a bunch of "includes" (way above)mostly tied to a class that does security and well formed check
when inluded they pass each related $_SESSION (such as phone).
Note: I do not have errors or anything else
BUT:
why is the following happening?
if I echo $phone value as per my comments below the final sql (an update) does its job

if I comment the phone echo, then its value dies below
if ($id_results!=$id etc....

As a direct result if I echo the final sql nothing's happening
but I re-pass $phone as a session or simply as an echo (below the if($id_results.....)
then all cranks on OK

I do not understand the reason?
// the section I ref to:
while($row = mysql_fetch_array($result))
{
$id_results=$row['id'];
$phone_results=$row['phone'];
$name_results=$row['name'];
}

// As you see I echo the $phone value (not related to that "While" it's OK!)
// so I should have that value active and existing
/*
echo"phone: $phone<p>";
*/
if ( $id_results!=$id && $phone_results == $phone)
$phone=$_SESSION['phone'];
//echo"phone: $phone";
// A new user (ID) but same location so we insert its details in rating_results

{
$time_in=time();
$vote="1";
$conn=db_connect();
$head_cate_id=CleanDb($head_cate_id);
$head_category=CleanDb($head_category);
$sub_cate_id=CleanDb($sub_cate_id);
$sub_cate_title=CleanDb($sub_cate_title);
$name=CleanDb($name);
$phone=CleanDb($phone); //echo"phone: $phone";

// lot of things happening such as math about time in, avaraging rating with existing rating etc..
and a final update
$sql= etc...

cmarshall

1:12 pm on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please excuse me for being thick, but I can't figure out what the problem is from the above explanation.

henry0

3:24 pm on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry I was pulled away and I know it's not easy to depict.
the problem is that
the value $phone dies if not passed again just below the "if" line.
could even be as simple as echoing it! (as per my commented lines)
<<<<
if ( $id_results!=$id && $phone_results == $phone)
//$phone=$_SESSION['phone'];
//echo"phone: $phone";
>>>>

if I simply echo it as a var or as a session then the rest of the script grabs it and the whole thing works
BUT this value is already there (from an above section of the script) it exists as session passed via an included file.

why below the if line the script does not get it
it's like if as soon as below the if line its value vanishes?

cmarshall

3:30 pm on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is really weird.

It isn't a reference variable, is it?

If you declare it as global, does that solve it?

henry0

3:35 pm on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is it, you are correct. Thanks
as is it only exists within the global scope of a function!