How to pass a numeric value as $9 = $_POST["Queensland"];

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oavs
    New Member
    • Jul 2010
    • 4

    #1

    How to pass a numeric value as $9 = $_POST["Queensland"];

    Hi
    I am having a bizarre problem with something so simple.

    I have a form that has a variables with numbers "9", "12" and "13" etc.. I can't seem to post the value using
    Code:
       $9 = $_POST["Queensland"];
    etc. as PHP not accepting << $9 >> as the variable.

    What I need once the form posts the value, on the second page I want to be able to display the one of the selected value as Queensland or New South Wales or ACT .

    Now the second problem I can see because numbers entered as the "value" represents the Freight in Dollars and some of the values are the same. In view of this I want to display the correct STATE names when they are selected on my second page following my form.

    So if someone selects "Queensland " then I want to be able to pass this as "Queensland " to the second page. I don't want to change the numerical values because they are working at the moment to calculate the freight user selects depending on the STATE they select.

    I would very much appreciate a solution to this.Please if you don't my give me the complete solution as I am not much of an expert in PHP or java.

    Thanks


    In the form I have STATE names as follows -
    Code:
      <select name="freight_fee_($)" class="field select medium" id="freight_fee_($)"  tabindex="14" >
        <option value="9">Queensland</option>
        <option value="12">New South Wales</option>
        <option value="12">ACT</option>
        <option value="13">Victoria</option>
        <option value="14">South Australia</option>
        <option value="16">Western Australia</option>
        <option value="15">Northern Territory</option>
        <option value="15">Tasmania</option>
      </select>
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    You cannot name your variables starting with numbers.
    You may start with an underscore if you are morally opposed to letters: $_9

    For you second problem, let me give another suggestion. You don't really want to tie your state with the freight like that. If that is where you are defining your freight and I do some very easy manipulation, I think that I could make your program register to send me something for $0 freight. You also cannot send two values as one (atleast without using arrays).

    Another approach would be to give a number to each state, or have the state codes (QLD, NSW, SA, etc) as your values, which is further processed in your processing script which keeps the $'s away from your users. With regards to showing users the freight, either have a static HTML list which they can look at, or write a simple javascript which will change the value of a uneditable input box, or even a HTML text block to the freight depending on the state selected.

    Hope that helps.

    Comment

    • oavs
      New Member
      • Jul 2010
      • 4

      #3
      Thanks I know I have done it the wrong way but took me a whole week to get it to work and I am not going to change unless someone shows me in detail. I am not opposed to under scores $_9 but if I do that on my first form then it will not do the calculation.

      Have a look at the site first before you comment to see how it works. http://www.photooncanvas.com.au/step-1.php


      Those STATE values are part of the on screen calculation. Not sure how else I could achieve what I have so far.

      Thanks you for your advise

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        Thanks I know I have done it the wrong way but ...
        My teacher would say: "No buts. Go back and fix it than."

        :)

        ..took me a whole week to get it to work and I am not going to change unless someone shows me in detail...
        Its simple really. $9 is wrong as TheServant already pointed out and its not going to work.

        Looking at your code I would first change this:

        Code:
        <select name="freight_fee_($)"...
        into somethin like this:

        Code:
        <select name="freight_fee" ...
        and this:

        Code:
        <option value="9">Queensland</option>
        into something like this:

        Code:
        <option value="Queensland">Queensland</option>
        .
        .
        .
        <option value="ACT">ACT</option>
        .
        .
        So when your user selects lets say "Queensland " and submits the form your $_POST['freight_fee'] would be "Queensland " or if your user selects "ACT" your $_POST['freight_fee'] would be "ACT". Basicly whatever is selected now is stored in $_POST['freight_fee']. Now you can use some if else or switch blocks or maybe some other ways to find out costs.

        Comment

        • oavs
          New Member
          • Jul 2010
          • 4

          #5
          Ok Thanks. But ..but.. that's not going to work as I have calculations on the first form based on the STATE selection which adds to the final amount before it is posted to the next page.

          I understand what you are saying in regards to matching the value with the name and that is how I would have done it normally but because the freight depends on which STATE it is selected that is why I ended up doing the way it is now.

          Now you can use some if else or switch blocks or maybe some other ways to find out costs.
          that is the answer I am looking for.

          Thanks
          Last edited by Dormilich; Jul 22 '10, 11:36 AM. Reason: fixing tags

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            Originally posted by oavs
            Ok Thanks. But ..but.. that's not going to work as I have calculations on the first form based on the STATE selection which adds to the final amount before it is posted to the next page.

            I understand what you are saying in regards to matching the value with the name and that is how I would have done it normally but because the freight depends on which STATE it is selected that is why I ended up doing the way it is now.

            that is the answer I am looking for.

            Thanks

            that is the answer I am looking for.
            What? if and else statements? He's just saying that you should use logic to control flow of your program.

            Those are like bricks, not the solution, the solution depends on what you need it to do.

            Dan
            Last edited by Dormilich; Jul 23 '10, 05:39 AM. Reason: fixing quote tags

            Comment

            Working...