Page 1 of 1

Variable Help!

Posted: Fri Mar 13, 2009 1:53 pm
by nishmgopal
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi Guys

I have two pages...page 1 looks like:

Code: Select all

$query = "SELECT * FROM Job_ID";
    $result = mysql_query($query);
    
    echo "<h1 class='title2'>Upcoming Project Roles</h1>
    <p>From the menu below please select the Project Role:</p>
     
    <form id='form2' method='post' action='go.php'>
   <p>
    <label>
 <select name='job' id='job'>";
    
   while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
       $Job_ID=$row['Job_ID'];
       $Job_Name= $row['Job_Name'];
      
     
  echo "<option value=\"$Job_Name\">$Job_Name</option>";
   }
I am trying to store the $Job_ID and $Job_Name as a session variable...and my code for this is (at the top of page1)

Code: Select all

 
Session_Start();
$_SESSION['$Job_ID']=$_POST['$Job_ID'];
$_SESSION['Job_Name']=$_POST['Job_Name']
And I am trying to use these variables in page2 as:

Code: Select all

<div class="title2"> <? echo $_SESSION['Job_ID'] echo $_SESSION['Job_Name'] ?> Specification:</div>
But this doesnt work. Can any1 tell me what I am doing wrong please.

Thank you


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:21 pm
by requinix

Code: Select all

$_SESSION['$Job_ID']=$_POST['$Job_ID'];
Why the $s?

(That's a hint, by the way.)

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:25 pm
by nishmgopal
sorry that was my fault, I fixed that error so now there is no $ and it still doesnt work!

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:51 pm
by pickle
Does page2 have a call to session_start() as well?

Also, I'd strongly suggest doing some safety checking, rather than pretty much just displaying what the user puts in $_POST. What if I $_POSTed 'Job_name' to be:

Code: Select all

<script type = "text/javascript">window.location.href = "http://somerandomdirtypornsite.com"</script>

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:56 pm
by nishmgopal
the job name is selected as a drop down menu which is generated by a sql query. the values the user can pick are set by what is in the table.

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:56 pm
by nishmgopal
yes page2 does have session start.

Re: Variable Help!

Posted: Fri Mar 13, 2009 2:57 pm
by requinix
You're also missing a semicolon in the third bit of code.

You still haven't explained what "doesn't work" means.

Re: Variable Help!

Posted: Fri Mar 13, 2009 6:07 pm
by pickle
nishmgopal wrote:the job name is selected as a drop down menu which is generated by a sql query. the values the user can pick are set by what is in the table.
Just because you've set up a form that all users can use, doesn't mean they will use it. It's pretty much trivial to submit one's own data to a page. Don't rely on user data ever.