Announcement

Collapse
No announcement yet.

Passing Variables to cgi

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing Variables to cgi

    I've got a web page I'm working on that allows a user to input data, click a button, and save the data to a MySQL database.

    Up to this point I've been using simple PHP scripts. My customer now wants to be able to do a lot of things with the data other than store it. I think this part would be much quicker if I use cgi, since I'm much more familiar with PBCC syntax than PHP.

    I know with PHP you can use POST and use the values stored within the variables.

    For cgi with PB, how would you pass the values of the variables to the cgi program?
    sigpicMark Pruitt
    [email protected]

    http://ezreregister.com
    Manage 3rd party BlackBerry software registration codes.

    It's not the only way to do it...just the EZ way!

  • #2
    Information is typically passed to a CGI program/script through it's environment. If the URL contains query parameters (stuff after a "?" in the URL) then it's available in the environment variable QUERY_STRING and the method that was used is specified in REQUEST_METHOD. If it's data that's been POSTed to you, then it's part of the payload of the request and is passed to you as standard input. In other words, you'd read it like you'd read standard input from a keyboard or redirected file. Commonly used servers like Apache and IIS follow this convention, but a proprietary Windows server may do things differently. If you're using IIS, there's a list of some of the environment variables passed to your program, here's a description of some of them (it's an article about ColdFusion, but it applies generally) and there's some more information TechNet as well.

    Keep in mind that POSTed data may be encoded, and multipart form data will actually have each submitted value in it's own "section" of the data; this is how things like file uploads are handled. Your CGI program would be responsible for handling that.
    Last edited by Mike Stefanik; 27 Mar 2008, 03:31 PM. Reason: Added the links
    Mike Stefanik
    sockettools.com

    Comment


    • #3
      php does not 'post', a html page which has a form with an action (url) and method (post) will post input elements where the name attribute is set.
      This name attribute should be used to split or read the data.

      Since i use ASP.NET which already breaks these things up i don't remember how to obtain the values per name.
      But afaik pb's cgi inc has a readdata (or similar named) function to read the posted data which is provided via stdin.

      Note that the ID attribute is often confused with name for an element.
      ID is used for inside the html like for javascript purposes etc..
      The name is used for data separation.

      Good luck
      hellobasic

      Comment


      • #4
        There are several different ways to do this.
        are you using a web form?

        the html:
        Code:
        <html>
        <body>
        <form method="post" action="cgi/yourProgram.exe">
        element one <input type="text" name="var1"><br>
        element two <input type="text" name="var2"><br>
        <input type="submit" value="submit">
        </form>
        </body>
        </html>
        the cgi would look like this
        Code:
        ' yourProgram.bas
        #include "pbcgi.inc"
        function pbmain()
          local sParams as string
          local var1 as string
          local var2 as string
          
          sParams=readCGI()
        
          var1=cgiParam(sParams,"var1")
          var2=cgiParam(sParams,"var2")
        
          writeCGI "<html><body>"
          writeCGI "you sent "+var1+" and "+var2  
          writeCGI "</body></html>
        end function
        Last edited by Shawn Anderson; 27 Mar 2008, 04:47 PM.

        Comment


        • #5
          Such simple examples should be in the source forum.
          Often on the internet you can only find overly complex examples.

          To the point, great..
          hellobasic

          Comment


          • #6
            Originally posted by Edwin Knoppert View Post
            Such simple examples should be in the source forum.
            Often on the internet you can only find overly complex examples.

            To the point, great..
            Should have read my tutorials. Lots of good stuff in there
            Software makes Hardware Happen

            Comment


            • #7
              ; your expaYou guys are great, more than enough info to get started.

              Shawn, yes I'm using forms, your example is very clear.

              Joe, I'm all over the tutorial!

              Thanks everyone.
              sigpicMark Pruitt
              [email protected]

              http://ezreregister.com
              Manage 3rd party BlackBerry software registration codes.

              It's not the only way to do it...just the EZ way!

              Comment


              • #8
                Originally posted by Edwin Knoppert View Post
                Such simple examples should be in the source forum.
                Those simple examples ship with the compiler.

                Look under SAMPLES\INTERNET\CGI

                Comment


                • #9
                  It does not.. on my computer

                  ??
                  hellobasic

                  Comment


                  • #10
                    Originally posted by Joe Byrne View Post
                    Should have read my tutorials. Lots of good stuff in there
                    I love that cookie example.

                    Place this url: http://www.basicrocks.com/ in your profile.
                    Way easier for us.
                    hellobasic

                    Comment


                    • #11
                      Originally posted by Edwin Knoppert View Post
                      It does not.. on my computer
                      Just checked: It ships with PB/CC (which seems to be the 'natural' choice for CGI), not with PB/WIN. That's why I only checked the PB/CC samples, knowing it would be there, because I studied it.

                      Sorry for the confusion.

                      Comment


                      • #12
                        Place this url: http://www.basicrocks.com/ in your profile.
                        The forum 'profile' seems to allow just one web site, and since I have a primary site already listed there .....

                        I could put it in my signature line, but I really dislike long signature lines.

                        So I guess for now, you'll have to bookmark the site
                        Software makes Hardware Happen

                        Comment


                        • #13
                          >So I guess for now, you'll have to bookmark the site

                          Geeh Joe, i think you want to keep me stupid

                          hellobasic

                          Comment


                          • #14
                            Geeh Joe, i think you want to keep me stupid
                            Na, I've seen your coding..... nobody could ever call you stupid!
                            Software makes Hardware Happen

                            Comment


                            • #15
                              Originally posted by Joe Byrne View Post
                              Na, I've seen your coding..... nobody could ever call you stupid!
                              That was my brother
                              hellobasic

                              Comment

                              Working...
                              X