#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0

    Pass variable value from one page to another


    Hello guys,

    I'm trying to pass variable value from one php script to another. The answer is probably easy but I'm confused. So let's say that I have 4 company names (the values below are retrieved from the database)

    firstpage.php
    -------------
    Company A - View
    Company B - View
    Company C - View
    Company D - View

    secondpage.php
    ----------------
    Company A
    ->Car 1
    ->Car 2
    ->Car 3

    The view button will take you to secondpage.php. If for example I click the first View button then in the secondpage.php I want to take the value of the first company which is ''Company A''. According to the selection I will retrieve some data from the database and print them.
    Companies may be more or less than 4 with different names for different people (depends on your interests etc).

    I tried to use while loop and inside the while loop I added a session but when I use the session to the second page it just gets one value (if i click either first view, or second or third blah blah... I'm getting the same value.. eg. Company A).
    Hope it makes sense what I just said

    Thanks in advance for your help
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    why can't you simply use an URL parameter? Because that's the essence of it: You link to a page displaying information for a particular company.

    The purpose of a session is to hold global data (like the language) for a whole site or at least a group of pages. So it hardly fits here.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0
    i have hundreds of companies in the database... I can't create so many php scripts for each company. That's what you said right?

    So what I want is to have one page for all companies and I will print different staff according to each company (using mysql).

    Is that possible?
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by shieldcy
    i have hundreds of companies in the database... I can't create so many php scripts for each company. That's what you said right?
    No, I'm talking about a URL parameter. You have a single script receiving the particular company through a URL parameter:

    Code:
    http://yoursite.com/stuff.php?company=abc
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0
    ooooh yeah now I get it.
    Cool I'll give it a try! Thank you

    Can I write something like that?
    <a href="companypage.php?company=<?php $name ?>>
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Use
    PHP Code:
    echo urlencode($name); 
    to make sure $name doesn't break the URL.

    Note that every character except "a", ..., "z", "A", ..., "Z", "0", ..., "9", "-", ".", "_", "~" will result in an ugly percent encoding. So either define a "URL friendly" company identifier, or use number IDs (which also allow fast database lookup).
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0
    I see! appreciate ur help, thank you.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    8
    Rep Power
    0
    edit: oops never mind, it was a really silly question :P sorryyy!
  16. #9
  17. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    New York
    Posts
    28
    Rep Power
    0
    Thanks for giving him a solution.Actually i have some problem with the same issue.Now i cleared with your solution.

IMN logo majestic logo threadwatch logo seochat tools logo