Using Sessions!

Ok, this is my first project in which i use sessions!

My impression from my reading is i just need to use this 'session_start();' i have it placed in the first line on my pages.    This works fine for me on my first page. then when i go to the second page it only half works.. here is my code for the second page..

<?php
session_start();
require 'function.php';

$sql = "select * from vin where vin='".$_SESSION[vin]."'";
$detail_report ='<br>Sql Statement run :' .$sql;
$result = mysql_query($sql,$conn) or die(mysql_error());
$vin = mysql_fetch_array($result);
                  echo '<br> '.$vin['vin'];
                  echo '<br> '.$vin['make'];
                  echo '<br> '.$vin['model'];
                  echo '<br> '.$vin['year'];

$sql = "select * from customer where customer_id='".$vin['currentownerID']."'";
$detail_report ='<br>Sql Statement run :' .$sql;
$result = mysql_query($sql,$conn) or die(mysql_error());
$customer = mysql_fetch_array($result);
                  echo '<br> '.$customer['firstname'].' '.$customer['lastname'];
                  echo '<br> '.$customer['address'];
                  echo '<br> '.$customer['city'].', '.$customer['state'].' '.$customer['zip'];
                  echo '<br> '.$customer['phone'];
                  echo '<br> '.$customer['phone2'];
                  echo '<br> '.$customer['notes'];

$sql = "select * from services";
$result = mysql_query($sql,$conn) or die(mysql_error());
$services = mysql_fetch_array($result);
$servicesrows = mysql_num_rows($result);

echo '<br><br><br>number of rows in the serivce table'.$servicesrows;

while ($catagoryArray = mysql_fetch_array($result)) {
                        // give a name to the fields
                        echo '<br>'. $catagoryArray['name'];

                  }

?>



Ok now the first time this page is run it works if it is refreshed at all or anything the session value is empty so it just pulls empty queries from the databse!? i know the session is still active cause when i go back to the previous page my session still works there.

Is there another command or something that i am missing?
LVL 2
mightofnightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheUnkindCommented:
I think you forgot to put " or ' in $_SESSION[vin]. so it will be $_SESSION['vin'] or $_SESSION["vin"].
0
d_tanCommented:
It is good programming practice to include the index as a string as TheUnkind mentioned.  Read http://jp2.php.net/types.array for more details.

That being said, it is probably the case that php is not quoting the vin for you.

Here's a good tip for ya. . .use print_r.

If you are unsure of what's in the session array. . .

echo "<pre>";
print_r( $_SESSION );
echo "</pre>";
exit();

dtan
0
mightofnightAuthor Commented:
Hum Thanks guys ireally appreciate the print_r statement whats the <pre></pre> i am not famiular with that tag? Also what does the prupose of the exit(); serve?

The problem must have been with my code cause after i posted i just passed on the variable using get so that i didnt' have to stop.  Now i changed it back to the $_SESSION['vin'] and it works.. it still worked with out the '.  the first examples i learned on never used thoes in array's so i have been tryign to change my habbits :P.


also how do you get the session id? i was going to base a statement on the vin but just realized when i went to write the code that i really needed the session id?
0
d_tanCommented:
The pre tags are html.  . . it just helps when reading the debug information from the print_r.  exit is the same as die().  It stops the script from executing after that point.  I use those 4 lines for debugging purposes.  It is not necessary to include the pre's or the exit.

there is a function session_id().  Also there is a constant defined as SID.  I suggest reading the php manual on sessions.  This will give you a good handle on sessions and might save ya a few headaches along the way. . .

dtan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mightofnightAuthor Commented:
Thanks d_tan!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.