Variable Help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Variable Help!

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variable Help!

Post by requinix »

Code: Select all

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

(That's a hint, by the way.)
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Variable Help!

Post by nishmgopal »

sorry that was my fault, I fixed that error so now there is no $ and it still doesnt work!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Variable Help!

Post 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>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Variable Help!

Post 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.
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Variable Help!

Post by nishmgopal »

yes page2 does have session start.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variable Help!

Post by requinix »

You're also missing a semicolon in the third bit of code.

You still haven't explained what "doesn't work" means.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Variable Help!

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply