12 Replies Latest reply on Jul 23, 2008 1:36 AM by Newsgroup_User

    Problems with php code

      Hello,
      I am trying to create a php login system and am having problems getting the code to work.


      The code runs but i constanly recive the wrong username or password error, I think the problem is linking the first page to the second becuase i tried top get the second page to echo "$myusername" and echo "$mypassword" but the page appeard blank, also i inserted blank feilds into my database for password and username and the page then logged in, this is the code for the login pages.

      Help greatly appriciated, thanks

        • 1. Re: Problems with php code
          Ben M Adobe Community Professional
          The only thing that jumps out at me is the deprecated function session_register. I looked over at the php manual just for quick reference and it should be written:

          session_start();
          $_SESSION['myusername'];
          $_SESSION['mypassword'];

          Before the form is submitted try this. Print $count so that you can make sure 1 result is being returned. If 1 is not being returned, then there is something wrong somewhere else in the code.
          • 2. Re: Problems with php code
            Level 7
            James,

            If $count doesn't show a result as SnakEyez02 suggests, then take a look at
            how you are building your SQL query string. I think that you have to do
            something like

            $sql="SELECT * FROM $tbl_name WHERE username=" . $myusername . " and
            password=" . $mypassword;

            (Notice the dots in the string; they're hard to see)

            Not exactly sure of the syntax but I don't think that you can embed the
            username and password directly in the statement.

            HTH

            Steve

            "SnakEyez02" <webforumsuser@macromedia.com> wrote in message
            news:g5su30$ijq$1@forums.macromedia.com...
            > The only thing that jumps out at me is the deprecated function
            > session_register. I looked over at the php manual just for quick
            > reference and
            > it should be written:
            >
            > session_start();
            > $_SESSION['myusername'];
            > $_SESSION['mypassword'];
            >
            > Before the form is submitted try this. Print $count so that you can make
            > sure
            > 1 result is being returned. If 1 is not being returned, then there is
            > something wrong somewhere else in the code.
            >


            • 3. Re: Problems with php code
              Level 7
              Steve wrote:
              > I think that you have to do
              > something like
              >
              > $sql="SELECT * FROM $tbl_name WHERE username=" . $myusername . " and
              > password=" . $mypassword;

              No, that won't work. The username and password are text fields, so must
              be in quotes. The original code is correct. An alternative way of
              writing it would be like this:

              $sql="SELECT * FROM $tbl_name WHERE username='" . $myusername . "' and
              password='" . $mypassword . "'";

              However, that's unnecessarily complex.

              --
              David Powers, Adobe Community Expert
              Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
              Author, "PHP Solutions" (friends of ED)
              http://foundationphp.com/
              • 4. Re: Problems with php code
                pancho1991 Level 1
                "david powers" is right.. the username and password must use quotes as they are text fields..

                bye

                Vuelos Baratos
                River Plate
                Ganar Dinero en Internet
                Trailers de Peliculas
                Futbol Gratis por Internet
                • 5. Re: Problems with php code
                  Level 7
                  Yep, left those out. And I agree; if the original code is correct, that's
                  much easier. I just didn't realize you could reference variables in-line
                  like that with PHP. Thanks for the tip.

                  I'm curious to know if James is running PHP 4.x or 5.x, and.whether or not
                  he is using an encryption function like md5() when he writes the password to
                  the database.


                  "David Powers" <david@example.com> wrote in message
                  news:g5tc3n$2s7$2@forums.macromedia.com...
                  > Steve wrote:
                  >> I think that you have to do something like
                  >>
                  >> $sql="SELECT * FROM $tbl_name WHERE username=" . $myusername . " and
                  >> password=" . $mypassword;
                  >
                  > No, that won't work. The username and password are text fields, so must be
                  > in quotes. The original code is correct. An alternative way of writing it
                  > would be like this:
                  >
                  > $sql="SELECT * FROM $tbl_name WHERE username='" . $myusername . "' and
                  > password='" . $mypassword . "'";
                  >
                  > However, that's unnecessarily complex.
                  >
                  > --
                  > David Powers, Adobe Community Expert
                  > Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
                  > Author, "PHP Solutions" (friends of ED)
                  > http://foundationphp.com/


                  • 6. Re: Problems with php code
                    Level 1
                    Hello, thanks guys. I changed the method="post" to method=POST and it all seems to be working now, i dont know what php im running on i think its 5 but its on my virtual server and i dnt know, i do plan to use md5 but, i just thought illd get the start first and develop it later.

                    Can any body recommend any good php tutorial websites as i only just started learning php 2 weeks ago as im only 15 and would like sum practice codes to have a go at,
                    • 7. Re: Problems with php code
                      Ben M Adobe Community Professional
                      There are plenty of PHP websites out there with tutorials. It's hard to really pin it down because I pick and choose as I learned programming way back when and started with VB and C++. So I had a concept of programming before PHP. If your school offers a class like that in your high school and you are thinking about getting into programming that is a good method.

                      David who responded earlier also makes some good books. And don't forget about the Adobe website. There are Dreamweaver specific tutorials here.

                      And lastly if you need to know the PHP version make a blank php document with the following on the page:

                      <? phpinfo(); ?>

                      That will show you the PHP version and the settings for PHP on your server.
                      • 8. Re: Problems with php code
                        Level 7
                        .oO(SnakEyez02)

                        > And lastly if you need to know the PHP version make a blank php document with
                        >the following on the page:
                        >
                        > <? phpinfo(); ?>

                        A beginner should learn it the right way:

                        <?php phpinfo(); ?>

                        Short open tags are ugly and highly unreliable.

                        Micha
                        • 9. Re: Problems with php code
                          Level 7
                          .oO(james1892)

                          >Hello, thanks guys. I changed the method="post" to method=POST

                          Huh? If at all it should be the other way round: method="post" is
                          correct and recommended.

                          >and it all seems
                          >to be working now, i dont know what php im running on i think its 5 but its on
                          >my virtual server

                          You run a virtual server and don't know what software is installed?

                          >and i dnt know, i do plan to use md5 but

                          And what does MD5 have to do with this all?

                          You scare and confuse me.

                          Micha
                          • 10. Re: Problems with php code
                            Level 7
                            Micha,

                            > You scare and confuse me.

                            If you had read all of the posts, you would have realized that James is 15,
                            and has been programming for two weeks. The reference to MD5 was an
                            exploratory question, and had to do with passwords not being recognized from
                            the database. A common programming mistake is to hash the passwords going
                            in, but failing to do so during a subsequent comparison. So, in context, it
                            was a perfectly logical conversation. I'm impressed that James knows as much
                            as he does for someone with so little experience.

                            Try to ease up a bit in your replies, especially to the younger folks. Even
                            if you're correct, you're coming across as being a bit arrogant, which I
                            hope is not your intention. People join in these lists to get help, or to
                            share their experience and expertise with others. If James, or anyone for
                            that matter, knew it all, they wouldn't need the list.

                            Steve





                            • 11. Re: Problems with php code
                              Level 7
                              On Sat, 19 Jul 2008 23:18:23 +0000 (UTC), "james1892"
                              <webforumsuser@macromedia.com> wrote:

                              >Hello, thanks guys. I changed the method="post" to method=POST and it all seems
                              >to be working now, i dont know what php im running on i think its 5 but its on
                              >my virtual server and i dnt know, i do plan to use md5 but, i just thought illd
                              >get the start first and develop it later.
                              >
                              > Can any body recommend any good php tutorial websites as i only just started
                              >learning php 2 weeks ago as im only 15 and would like sum practice codes to
                              >have a go at,


                              Not an online tutorial - but an truly excellent book on the subject is

                              Dreamweaver CS3 with CSS, Ajax and PHP by David Powers - another
                              excellent book, very readable style on how to produce good websites
                              with Dw. It is NOT like your typical guide to Dw – that just
                              regurgitates the help files - including the bits of Dw that should
                              have been binned - David guides you on best practice and the parts of
                              Dw to avoid.
                              http://foundationphp.com/egdwcs3/index.php

                              http://www.amazon.com/Essential-Guide-Dreamweaver-CS3-Ajax/dp/1590598598/ref=pd_bbs_1?ie=U TF8&s=books&qid=1216766004&sr=8-1





                              --

                              ~Malcolm~*...
                              ~*
                              • 12. Re: Problems with php code
                                Level 7
                                .oO(Steve)

                                >Micha,
                                >
                                >> You scare and confuse me.
                                >
                                >If you had read all of the posts, you would have realized that James is 15,
                                >and has been programming for two weeks. The reference to MD5 was an
                                >exploratory question, and had to do with passwords not being recognized from
                                >the database.

                                I missed the MD5 reference in your previous posting, so I was confused
                                about James mentioning it. Sorry for that.

                                >Try to ease up a bit in your replies, especially to the younger folks. Even
                                >if you're correct, you're coming across as being a bit arrogant, which I
                                >hope is not your intention. People join in these lists to get help, or to
                                >share their experience and expertise with others. If James, or anyone for
                                >that matter, knew it all, they wouldn't need the list.

                                Point taken.

                                Micha