Coding/form problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Coding/form problem

    Hi.


    I am just in the very early stages of learning Php and just need a
    little help.

    I have a form which includes values. However when I test it, the
    values are not added up and carried to the results page. I just
    wondered if you can spot whats wrong with it?


    This is the form on the page tourprice.php:

    <form name="frm_tourp rice" id="frm_tourpri ce" method="post"
    action="tourpri ce_processor.ph p">
    <table width="60%" border="0" cellspacing="0" cellpadding="3" >
    <tr>
    <td>Number of Adults </td>
    <td><input name="numAdults " type="text" id="numAdults"
    /></td>
    </tr>
    <tr>
    <td>Number of Children </td>
    <td><input name="numChildr en" type="text" id="numChildren "
    /></td>
    </tr>
    <tr>
    <td>Tour Name </td>
    <td><select name="tourName" id="tourName">
    <option value="500">Hig hlights of Argentina</option>
    <option value="700">Hig hlights of Western Canada</option>
    <option value="900">Egy ptian Pyramids and More</option>
    </select></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit"
    /></td>
    </tr>
    </table>
    </form>

    On the tourprice_calcu lator.php page it is supposed to add everything
    up depending on what you select and give you the correct cost. I keep
    getting a zero returned though.

    This is at the top of tourprice_calcu lator.php

    <?php
    $numAdult = $_POST['numAdults'];
    $numChild = $_POST['numChildren'];
    $basePrice = $_POST['tourName'];
    $tourPrice = (numAdult * basePrice) + (numChild * basePrice)
    ?>

    Further down on the page I have the following:

    Tour Price Calculator </h1>
    <p>The estimated cost of your tour is <strong><?php echo
    $tourPrice; ?></strong>.</p>
    <p>Price includes hotel, accommodation, and travel expenses during
    the tour. They do not include airfare to the starting destination.</p>
    <p><a href="tourprice .php">Calculate </a> another tour.</p>
    <p><a href="contact.p hp">Contact</a> one of our qualified
    agents.</p>


    Thanks very much for any help. Im a little confused with this one. I
    thought it might be some of the strings like $Adult $Adults $Children
    $Child etc that were wrong, but when I tried changing those it still
    comes up as zero.

    John


  • Andy Hassall

    #2
    Re: Coding/form problem

    On Wed, 26 May 2004 22:35:47 +0100, John <daffy@duck.com > wrote:
    [color=blue]
    >On the tourprice_calcu lator.php page it is supposed to add everything
    >up depending on what you select and give you the correct cost. I keep
    >getting a zero returned though.
    >
    >This is at the top of tourprice_calcu lator.php
    >
    ><?php
    >$numAdult = $_POST['numAdults'];
    >$numChild = $_POST['numChildren'];
    >$basePrice = $_POST['tourName'];
    >$tourPrice = (numAdult * basePrice) + (numChild * basePrice)[/color]

    Before you do anything else, modify your php.ini and set:

    error_reporting = E_ALL

    It would have clearly shown what was wrong here.

    Notice: Use of undefined constant numAdult - assumed 'numAdult' in
    /home/andyh/public_html/test.php on line 5

    Notice: Use of undefined constant basePrice - assumed 'basePrice' in
    /home/andyh/public_html/test.php on line 5

    Notice: Use of undefined constant numChild - assumed 'numChild' in
    /home/andyh/public_html/test.php on line 5

    Notice: Use of undefined constant basePrice - assumed 'basePrice' in
    /home/andyh/public_html/test.php on line 5

    Addition and multiplication aren't defined for strings, so you end up with a
    zero instead.

    You need to put $ in front of variable names.

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

    Comment

    • John

      #3
      Re: Coding/form problem

      On Wed, 26 May 2004 23:14:32 +0100, Andy Hassall <andy@andyh.co. uk>
      wrote:
      [color=blue]
      >On Wed, 26 May 2004 22:35:47 +0100, John <daffy@duck.com > wrote:
      >[color=green]
      >>On the tourprice_calcu lator.php page it is supposed to add everything
      >>up depending on what you select and give you the correct cost. I keep
      >>getting a zero returned though.
      >>
      >>This is at the top of tourprice_calcu lator.php
      >>
      >><?php
      >>$numAdult = $_POST['numAdults'];
      >>$numChild = $_POST['numChildren'];
      >>$basePrice = $_POST['tourName'];
      >>$tourPrice = (numAdult * basePrice) + (numChild * basePrice)[/color]
      >
      > Before you do anything else, modify your php.ini and set:
      >
      > error_reporting = E_ALL[/color]

      I checked the ini file and it seems to already be set.

      This is what it says:

      error_reporting = E_ALL & ~E_NOTICE

      [color=blue]
      > It would have clearly shown what was wrong here.[/color]

      How do you get it to show all these errors? When I go to validate the
      documents in Dreamweaver it doesn't come up with any.
      [color=blue]
      >Notice: Use of undefined constant numAdult - assumed 'numAdult' in
      >/home/andyh/public_html/test.php on line 5
      >
      >Notice: Use of undefined constant basePrice - assumed 'basePrice' in
      >/home/andyh/public_html/test.php on line 5
      >
      >Notice: Use of undefined constant numChild - assumed 'numChild' in
      >/home/andyh/public_html/test.php on line 5
      >
      >Notice: Use of undefined constant basePrice - assumed 'basePrice' in
      >/home/andyh/public_html/test.php on line 5
      >
      > Addition and multiplication aren't defined for strings, so you end up with a
      >zero instead.
      >
      > You need to put $ in front of variable names.[/color]

      ?php
      $numAdult = $_POST['numAdults'];
      $numChild = $_POST['numChildren'];
      $basePrice = $_POST['tourName'];
      $tourPrice = (numAdult * basePrice) + (numChild * basePrice)

      Do I put the $ within these brackets as well so I have...?

      ?php
      $numAdult = $_POST['$numAdults'];
      $numChild = $_POST['$numChildren'];
      $basePrice = $_POST['$tourName'];
      $tourPrice = ($numAdult * $basePrice) + ($numChild * $basePrice)


      And would that need to go on the inital page too within the form?
      e.g.

      <td>Number of Adults </td>
      <td><input name="$numAdult s" type="text" id="$numAdults "
      /></td>


      Thanks

      John



      Comment

      • John

        #4
        Setting Up MySQL?

        Hello.

        I'd like to set up MySQL to run locally on my system but I'm having a
        little trouble.

        The one I have in the phpdev folder on drive C that I got from
        firepages doesn't work.

        I have downloaded it from the MySQL website, and installed to c:, but
        when I goto c:\mysql\bin and click on WinMySqlAdmin it comes up with
        an error saying that LIBMYSQL.DLL was not found.

        I have tried reinstalling but it makes no difference. If you know
        what the problem is I'd be very grateful for your help.

        Thanks

        John


        Comment

        • Tony P.

          #5
          Re: Setting Up MySQL?

          In article <pkalb0hv5ktlqp ahg8sch7lih4p23 o8kei@4ax.com>, hello@hi.com
          says...[color=blue]
          > Hello.
          >
          > I'd like to set up MySQL to run locally on my system but I'm having a
          > little trouble.
          >
          > The one I have in the phpdev folder on drive C that I got from
          > firepages doesn't work.
          >
          > I have downloaded it from the MySQL website, and installed to c:, but
          > when I goto c:\mysql\bin and click on WinMySqlAdmin it comes up with
          > an error saying that LIBMYSQL.DLL was not found.
          >
          > I have tried reinstalling but it makes no difference. If you know
          > what the problem is I'd be very grateful for your help.
          >
          > Thanks
          >
          > John[/color]

          Hmmm... is the my.ini file in your system directory? Because if it's not
          it probably is causing the problem. It's what tells MySQL where
          everything is.

          Comment

          • John

            #6
            Re: Setting Up MySQL?

            On Mon, 31 May 2004 03:58:42 GMT, Tony P.
            <kd1s@nospample ase.verizon.rea llynospam.net> wrote:
            [color=blue]
            >In article <pkalb0hv5ktlqp ahg8sch7lih4p23 o8kei@4ax.com>, hello@hi.com
            >says...[color=green]
            >> Hello.
            >>
            >> I'd like to set up MySQL to run locally on my system but I'm having a
            >> little trouble.
            >>
            >> The one I have in the phpdev folder on drive C that I got from
            >> firepages doesn't work.
            >>
            >> I have downloaded it from the MySQL website, and installed to c:, but
            >> when I goto c:\mysql\bin and click on WinMySqlAdmin it comes up with
            >> an error saying that LIBMYSQL.DLL was not found.
            >>
            >> I have tried reinstalling but it makes no difference. If you know
            >> what the problem is I'd be very grateful for your help.
            >>
            >> Thanks
            >>
            >> John[/color]
            >
            >Hmmm... is the my.ini file in your system directory? Because if it's not
            >it probably is causing the problem. It's what tells MySQL where
            >everything is.[/color]

            Hi. No I can't seem to find anything in the system directory.

            Which folder in MySql can I find the file to copy? I had a look in
            the Bin folder but it seems to be all .exe's in there. Do I just
            leave the .DLL file where it is, or does that need copying to system
            as well?

            Thanks for your help

            John



            Comment

            • Andy Hassall

              #7
              Re: Coding/form problem

              On Sun, 30 May 2004 20:25:28 +0100, John <hello@hi.com > wrote:
              [color=blue]
              >On Wed, 26 May 2004 23:14:32 +0100, Andy Hassall <andy@andyh.co. uk>
              >wrote:
              >[color=green]
              >>On Wed, 26 May 2004 22:35:47 +0100, John <daffy@duck.com > wrote:
              >>[color=darkred]
              >>>On the tourprice_calcu lator.php page it is supposed to add everything
              >>>up depending on what you select and give you the correct cost. I keep
              >>>getting a zero returned though.
              >>>
              >>>This is at the top of tourprice_calcu lator.php
              >>>
              >>><?php
              >>>$numAdult = $_POST['numAdults'];
              >>>$numChild = $_POST['numChildren'];
              >>>$basePrice = $_POST['tourName'];
              >>>$tourPrice = (numAdult * basePrice) + (numChild * basePrice)[/color]
              >>
              >> Before you do anything else, modify your php.ini and set:
              >>
              >> error_reporting = E_ALL[/color]
              >
              >I checked the ini file and it seems to already be set.
              >
              >This is what it says:
              >
              >error_reportin g = E_ALL & ~E_NOTICE[/color]

              Which says to hide (because of the ~) all 'notice' level warnings. Change it
              to read exactly as I posted above.
              [color=blue][color=green]
              >> It would have clearly shown what was wrong here.[/color]
              >
              >How do you get it to show all these errors? When I go to validate the
              >documents in Dreamweaver it doesn't come up with any.[/color]

              No idea about Dreamweaver, I've never used it. I just ran the script from a
              browser as normal.
              [color=blue][color=green]
              >>Notice: Use of undefined constant numAdult - assumed 'numAdult' in
              >>/home/andyh/public_html/test.php on line 5[/color][/color]
              [snip][color=blue][color=green]
              >> You need to put $ in front of variable names.[/color]
              >
              >?php
              >$numAdult = $_POST['numAdults'];
              >$numChild = $_POST['numChildren'];
              >$basePrice = $_POST['tourName'];
              >$tourPrice = (numAdult * basePrice) + (numChild * basePrice)
              >
              >Do I put the $ within these brackets as well so I have...?
              >
              >?php
              >$numAdult = $_POST['$numAdults'];[/color]

              Don't just pile $ signs in everywhere - put them in front of variables.
              [color=blue]
              >$numChild = $_POST['$numChildren'];
              >$basePrice = $_POST['$tourName'];
              >$tourPrice = ($numAdult * $basePrice) + ($numChild * $basePrice)[/color]

              What happened when you tried it?
              The $tourPrice line is now correct, but all the others are now wrong.
              [color=blue]
              >And would that need to go on the inital page too within the form?
              >e.g.
              >
              > <td>Number of Adults </td>
              > <td><input name="$numAdult s" type="text" id="$numAdults "[/color]

              No.

              --
              Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
              http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

              Comment

              • Tony P.

                #8
                Re: Setting Up MySQL?

                In article <djhmb09gr1g59j 63i6ifepef2sajj hk6hd@4ax.com>, hello@hi.com
                says...[color=blue]
                > On Mon, 31 May 2004 03:58:42 GMT, Tony P.
                > <kd1s@nospample ase.verizon.rea llynospam.net> wrote:
                >[color=green]
                > >In article <pkalb0hv5ktlqp ahg8sch7lih4p23 o8kei@4ax.com>, hello@hi.com
                > >says...[color=darkred]
                > >> Hello.
                > >>
                > >> I'd like to set up MySQL to run locally on my system but I'm having a
                > >> little trouble.
                > >>
                > >> The one I have in the phpdev folder on drive C that I got from
                > >> firepages doesn't work.
                > >>
                > >> I have downloaded it from the MySQL website, and installed to c:, but
                > >> when I goto c:\mysql\bin and click on WinMySqlAdmin it comes up with
                > >> an error saying that LIBMYSQL.DLL was not found.
                > >>
                > >> I have tried reinstalling but it makes no difference. If you know
                > >> what the problem is I'd be very grateful for your help.
                > >>
                > >> Thanks
                > >>
                > >> John[/color]
                > >
                > >Hmmm... is the my.ini file in your system directory? Because if it's not
                > >it probably is causing the problem. It's what tells MySQL where
                > >everything is.[/color]
                >
                > Hi. No I can't seem to find anything in the system directory.
                >
                > Which folder in MySql can I find the file to copy? I had a look in
                > the Bin folder but it seems to be all .exe's in there. Do I just
                > leave the .DLL file where it is, or does that need copying to system
                > as well?[/color]

                In the distribution source there are various example .ini files for
                different MySQL setups. I believe you copy one of those as my.ini to the
                boot drive's Win folder, be it WINNT or Windows.

                It's a really simple file:
                [mysqld]
                basedir=d:\mysq l
                datadir=d:\mysq l\data

                All it does is point to the MySQL base and data directories.

                Comment

                • John

                  #9
                  Re: Setting Up MySQL?

                  The problem is that I get the following message when I try and run the
                  winmysqladmin filein the bin folder "This application has failed to
                  start because LIBMYSQL.dll was not found." I need to get this bit
                  working first.

                  John

                  Comment

                  • Tony P.

                    #10
                    Re: Setting Up MySQL?

                    In article <j2smb0pmsi3b4v 5hkjnth1tpaor0i sk0ut@4ax.com>, hello@hi.com
                    says...[color=blue]
                    > The problem is that I get the following message when I try and run the
                    > winmysqladmin filein the bin folder "This application has failed to
                    > start because LIBMYSQL.dll was not found." I need to get this bit
                    > working first.
                    >
                    > John
                    >[/color]

                    It's because you my.ini file doesn't know where the base is.

                    It's located in drive:\{Install Dir}\Embedded\d ebug.

                    I have already posted a sample my.ini file, it's just two lines. One
                    tells the system where the base directory for MySQL is, the other where
                    the data is located.

                    Comment

                    • John

                      #11
                      Re: Setting Up MySQL?

                      On Mon, 31 May 2004 20:54:16 GMT, Tony P.
                      <kd1s@nospample ase.verizon.rea llynospam.net> wrote:
                      [color=blue]
                      >In article <j2smb0pmsi3b4v 5hkjnth1tpaor0i sk0ut@4ax.com>, hello@hi.com
                      >says...[color=green]
                      >> The problem is that I get the following message when I try and run the
                      >> winmysqladmin filein the bin folder "This application has failed to
                      >> start because LIBMYSQL.dll was not found." I need to get this bit
                      >> working first.
                      >>
                      >> John
                      >>[/color]
                      >
                      >It's because you my.ini file doesn't know where the base is.
                      >
                      >It's located in drive:\{Install Dir}\Embedded\d ebug.
                      >
                      >I have already posted a sample my.ini file, it's just two lines. One
                      >tells the system where the base directory for MySQL is, the other where
                      >the data is located.[/color]


                      I changed the my.ini file located in C:\Windows\syst em32 to what you
                      said in the second reply:

                      [mysqld]
                      basedir=C:\mysq l
                      datadir=C:\mysq l\data

                      And then I changed it again to what you said in the last reply for
                      where the dll file is located:

                      [mysqld]
                      basedir=C:\mysq l\Embedded\DLL\ debug
                      datadir=C:\mysq l\data

                      Neither of these made any difference I still get the same message
                      saying "This application has failed to start because LIBMYSQL.dll was
                      not found."



                      John


                      Comment

                      • Tony P.

                        #12
                        Re: Setting Up MySQL?

                        In article <av7nb0h6bloaki l34q69uc8gsglch cqbki@4ax.com>, hello@hi.com
                        says...[color=blue]
                        > On Mon, 31 May 2004 20:54:16 GMT, Tony P.
                        > <kd1s@nospample ase.verizon.rea llynospam.net> wrote:
                        >[color=green]
                        > >In article <j2smb0pmsi3b4v 5hkjnth1tpaor0i sk0ut@4ax.com>, hello@hi.com
                        > >says...[color=darkred]
                        > >> The problem is that I get the following message when I try and run the
                        > >> winmysqladmin filein the bin folder "This application has failed to
                        > >> start because LIBMYSQL.dll was not found." I need to get this bit
                        > >> working first.
                        > >>
                        > >> John
                        > >>[/color]
                        > >
                        > >It's because you my.ini file doesn't know where the base is.
                        > >
                        > >It's located in drive:\{Install Dir}\Embedded\d ebug.
                        > >
                        > >I have already posted a sample my.ini file, it's just two lines. One
                        > >tells the system where the base directory for MySQL is, the other where
                        > >the data is located.[/color]
                        >
                        >
                        > I changed the my.ini file located in C:\Windows\syst em32 to what you
                        > said in the second reply:
                        >
                        > [mysqld]
                        > basedir=C:\mysq l
                        > datadir=C:\mysq l\data
                        >
                        > And then I changed it again to what you said in the last reply for
                        > where the dll file is located:
                        >
                        > [mysqld]
                        > basedir=C:\mysq l\Embedded\DLL\ debug
                        > datadir=C:\mysq l\data
                        >
                        > Neither of these made any difference I still get the same message
                        > saying "This application has failed to start because LIBMYSQL.dll was
                        > not found."[/color]

                        Ah - I may have confused you when I stated system dir - system dir to me
                        = win dir. In any case, the original version belongs in c:\windows

                        You don't have to tell it where the DLL is - it knows based on the
                        basedir variable.

                        Comment

                        • Theo

                          #13
                          Re: Setting Up MySQL?

                          John <hello@hi.com > wrote in news:av7nb0h6bl oakil34q69uc8gs glchcqbki@
                          4ax.com:
                          [color=blue]
                          > basedir=C:\mysq l\Embedded\DLL\ debug
                          > datadir=C:\mysq l\data[/color]

                          just chiming in here, and I dont know if this is the root problem... but on
                          windows, all file paths must be in quotes:

                          so

                          C:\path should be "C:\path"

                          Comment

                          • Tony P.

                            #14
                            Re: Setting Up MySQL?

                            In article <Xns94FAB1F5B2B B8densnews123@2 16.168.3.44>,
                            invalid@noemail .com says...[color=blue]
                            > John <hello@hi.com > wrote in news:av7nb0h6bl oakil34q69uc8gs glchcqbki@
                            > 4ax.com:
                            >[color=green]
                            > > basedir=C:\mysq l\Embedded\DLL\ debug
                            > > datadir=C:\mysq l\data[/color]
                            >
                            > just chiming in here, and I dont know if this is the root problem... but on
                            > windows, all file paths must be in quotes:
                            >
                            > so
                            >
                            > C:\path should be "C:\path"
                            >[/color]

                            No, this is an ini file - no such rules apply.

                            Comment

                            • Theo

                              #15
                              Re: Setting Up MySQL?

                              Tony P. <kd1s@nospample ase.verizon.rea llynospam.net> wrote in
                              news:MPG.1b259a fa9555cd12989a4 b@news.verizon. net:
                              [color=blue]
                              > No, this is an ini file - no such rules apply.[/color]

                              example cut/paste from php.ini

                              extension_dir = "C:\php\extensi ons"

                              it might depend on the windows version. NT based ones require it. I dunno
                              about the others.

                              Comment

                              Working...