Makes sense, but where do we code the needed file?

In addBills.php or dbAccess.php?

    Originally posted by npereira
    Makes sense, but where do we code the needed file?

    In addBills.php or dbAccess.php?

    The code you just wrote

    if(class_exists.....

    is the code that ensures the dependency.

    if you created addBill.php and tried this

    <?php
    require_once('dbBills.php');
    
    //more code
    ?>

    you would get this on the screen:
    Please load dbAccess before you load dbBills.

    so you would then modify the code to this:

    <?php
    require_once('dbAccess.php');
    require_once('dbBills.php');
    
    //more code
    ?>

    at which point you would get this on the screen:
    Please load gloabals.php before you load dbAccess.php

    so you would then modify the code once more and get this:

    <?php
    require_once('globals.php');
    require_once('dbAccess.php');
    require_once('dbBills.php');
    
    //more code
    ?>

    Basically what you're doing is you're being nice to yourself.

    In a couple months or so when you're working up a new interface for this system and you try to reuse your objects you're probably not going to remember all of your dependencies, but your object files will. Then you'll get these nice error messages and fix them in a couple of seconds instead of getting the ugly php errors when you try to create instances of nonexistent classes and reference nonexistent constants. I have spent hours trying to find the bug in my database connection string just to discover that my globals.php file isn't loaded. This is why you make the individual files enforce their own dependencies.

      OH !

      So once we start codding the different addBills.html, editBills.html, etc, I will need to add theses dependencies to the top of the files!

      Ok, now I get it!.

      So , what's next?

      Dose it take this long to make a scipt file? W'ev been on this for what now, 2 weeks?

      Anyway, let's move on!

        this is only taking so long because you've never done it before. Do me a favor post up your current version of dbBills.php so I can see what's next.

          you have this in the top of the file

          <?php
          
            <?php

          remove the second one.

          Things that need to be fixed.

          1) Insert does not error check anything. Insert should make sure it has valid values before it attempts to execute the sql.

          2) Update does not make sure the fields currently contain data. What if the user Updates without a retrieval? Update should ensure that a record exists to be updated before attempting the update.

          3) DelRec is good

          4) IDList & Search we will work on after you fix the things mentioned in this post.

          5) Retrieve is good

          6) Get is good

          7) According to your code BillName, DueWhen & Amount can be anything including blank. BillName should have to be entered, DueWhen should be either the 1st or the 15st I think. Take a look back and see what kind of field this is in the database and it's excepted values then error check accordingly. Amount should have to be money i.e. nnn.nn - this will be a reg ex to check.

            Originally posted by drawmack
            you have this in the top of the file

            <?php
            
              <?php

            remove the second one.
            [/b]

            Done ! Oups!


            Things that need to be fixed.

            1) Insert does not error check anything. Insert should make sure it has valid values before it attempts to execute the sql.

            How do I check if it is a good value or not?


            2) Update does not make sure the fields currently contain data. What if the user Updates without a retrieval? Update should ensure that a record exists to be updated before attempting the update.

            How do I check that the id$ being updated is an existing ID in the database?


            7) According to your code BillName, DueWhen & Amount can be anything including blank. BillName should have to be entered, DueWhen should be either the 1st or the 15st I think. Take a look back and see what kind of field this is in the database and it's excepted values then error check accordingly. Amount should have to be money i.e. nnn.nn - this will be a reg ex to check.

            Your loosing me here! Remember, I'm not fluent in PHP!

              you want to check if the values you currently have in the class variables are valid as per the error checking you have set up in the set function.

              This about that statement and see if you can figure out a way to do this.

                as for checking if an id exists in the database, you can attempt to retrieve the associated record.

                as for checking that bill name is entered the function is strlen.

                as for checking that duewhen and billamount are valid the function you want is eregi.

                  Originally posted by drawmack
                  you want to check if the values you currently have in the class variables are valid as per the error checking you have set up in the set function.

                  This about that statement and see if you can figure out a way to do this.

                  I don't know!

                    Originally posted by drawmack
                    as for checking if an id exists in the database, you can attempt to retrieve the associated record.

                    as for checking that bill name is entered the function is strlen.

                    as for checking that duewhen and billamount are valid the function you want is eregi.

                    I have looked at the 'strlen' and 'eregi' but don't know how to code it!

                      Originally posted by npereira
                      I don't know!

                      what happens when you do this

                      function insert() {
                      if(!$this->Set('ID',$this->ID)) {
                      //set error return 0
                      } elseif {!this->Set('BillName',$this->BillName)) {
                      //set error return 0
                      }
                      } //end insert

                      start thinking about things.

                      My statement told you this it just did it in english.

                      You want to check the class variables by the error checking you implemented in the set method.

                        Originally posted by npereira
                        I have looked at the 'strlen' and 'eregi' but don't know how to code it!

                        if something is blank what is it's strlen? how can you use strlen to avoid a variable being blank?

                        search the web and read up on regular expressions to figure out how to use the eregi command. There is an excellent article on regular expressions on this site.

                          Originally posted by drawmack
                          what happens when you do this

                          function insert() {
                          if(!$this->Set('ID',$this->ID)) {
                          //set error return 0
                          } elseif {!this->Set('BillName',$this->BillName)) {
                          //set error return 0
                          }
                          } //end insert

                          Let me see!

                          if(!$this->Set('ID',$this->ID))
                          If $this->Set is not ID or $this->ID then .... return 0 ?

                          elseif {!this->Set('BillName',$this->BillName))
                          Same thing with this? if $this->Set is not BillName or $this->BillName then ... return 0?

                          Am I right? If not, let me know how to read the line!

                            Originally posted by drawmack
                            if something is blank what is it's strlen? how can you use strlen to avoid a variable being blank?

                            if (strlen != "")

                            ?

                              Originally posted by npereira
                              if(!$this->Set('ID',$this->ID))
                              Am I right? If not, let me know how to read the line! [/B]

                              it's actually a bit of a hack

                              you see what we do is we attempt to set $this->ID = $this->ID and pump the assignment through your set function which will take advanatage of your error checking. If this assignment fails then we know that we do not have a valid record to insert.

                                Originally posted by drawmack
                                http://www.php.net/strlen

                                The docs talk about assigning a value, and see if the value is like $

                                It does not mention anything about seeing if the value is ""?
                                Plus, it's not based with class, but we are. So this is VERY confusing!

                                  Originally posted by drawmack
                                  it's actually a bit of a hack

                                  you see what we do is we attempt to set $this->ID = $this->ID and pump the assignment through your set function which will take advanatage of your error checking. If this assignment fails then we know that we do not have a valid record to insert.

                                  So is this right? or not?

                                    if(strlen($var) < $minLength) {
                                    //our string is to short
                                    } elseif (strlen($var) > $maxlength) {
                                    //our string is to long
                                    }

                                    just modify the above code.