Jump to content

maxxd

Gurus
  • Posts

    1,657
  • Joined

  • Last visited

  • Days Won

    51

Posts posted by maxxd

  1. OK. First off, do what ginerjm suggests. Always turn on error reporting on your development server. Now, fun times.

     

    You're assigning $student_id the value from $_REQUEST['id'], using $_GET['id'] in the query, assigning $_SESSION['student_id'] the value from $_POST['student_id'], and using $student_id in the redirect header. It also seems that the database contains a learner_id field, which you compare to $_POST['learner_id']. The sheer volume of inconsistent data sources, names, and data transfer methods makes debugging a nightmare.

     

    I would recommend selecting the student id from the student_information when you select last_login_date. The id should be an auto-incremented primary key for the table, so you'll know it's an integer and safe for CRUD operations. Compare that to either $_GET['id'] or $_POST['id'] (I'd recommend you choose a transfer method and stick with it - as you can see, it's easy to get confused if you don't know where the data is coming from) to make sure you're dealing with the right student, then you can a) assign the database-retrieved value to $_SESSION['student_id'], b) use the database-retrieved value to update the student_information table, and c) append the database-retrieved value to the location header.

     

    All of that aside, print out the value of $student_id before and after the htmlentities() call and see what the value actually is. From the documentation:

    If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set. 
    
  2. Several things going on, but the one that's probably tripping you up is that you're not hashing your password before comparing it to the one in the database. I'm assuming (hoping, really) that the stored passwords are all hashed and not just plain-text. Ignoring the deprecated mysql_ functions, the invitation to SQL injection, and undeclared variables, this is probably why you're not logging in correctly even with legit credentials.

  3. You stated this in reply #7:

    Then the next age thatdisplays calls the login_check function which is shown below and at the point the session variables have no values.
    

    I'm assuming a bit of a typo on 'the next age thatdisplays' that was meant to read 'the next page that displays'. If you're redirecting, are you restarting the session on the target page with session_start()? If not, usually php will throw an error, but if your error reporting is off you'll never know that. Insert the lines jazzman1 suggests on the page to which you redirect and see if it give you an error about undefined variable $_SESSION. If so, start the session again and let us know what happens.

  4. I agree with Maq. What you've described above isn't really polymorphism (at least not so much as I understand the concept). What you'd do is create Apple, Pear, and Kiwi class files, the approach like this:

    $fruit = 'Apple';
    $produce = new $fruit();
    $res = $produce->calculate();
    
    $fruit = 'Kiwi';
    $produce = new $fruit();
    $res = $produce->calculate();
    
    $fruit = 'Pear';
    $produce = new $fruit();
    $res = $produce->calculate();
    

    This way Apple,. Kiwi, and Pear can all have wildly different methods of calculating whatever it is they're calculating and the calling implementation doesn't have to know a thing about any of it.

  5. Try removing the header("Location: view_dept.php") line from data1.php.

     

    You can close the database connection and then use exit(); to halt script processing. As it stands, by the way, your connection is closed by the page refresh and not the explicit close command. Also, you'll want to start using PDO or mysqli_ - the mysql_ functions have been deprecated for quite some time and are scheduled to be removed in the near-ish future.

  6. class Automobile implements iAutoDetails{
        private $_model;
    
        function __construct($model){
            $this->_model = new $model();
         }
    }
    
    interface iAutoDetails{
        public function getWheelBase();
    }
    
    class Mustang2013 extends Automobile{
        private $_wheels = '17 x 8';
    
        public function getWheelBase(){
            return $this->_wheels;
        }
    }
    
    class Mustang2012Boss302 extends Automobile{
        private $_wheels = '19 x 9';
    
        public function getWheelBase(){
            return $this->_wheels;
        }
    }
    
    $auto = new Automobile('Mustang2012Boss302');
    print("<p>{$auto->getWheelBase()}</p>");
    //prints 17 x 8
    $auto2 = new Autmobile('Mustang2013');
    print("<p>{$auto2->getWheelBase()}</p>");
    //prints 19 x 9
    

    I think the issue is your current object setup. Personally, I'd do the above - that way it really doesn't matter at all what automobile you're instantiating, you know you can call getWheelBase() and you'll get the proper wheel base measurements. Obviously, you'd put any and all common functionality in the parent class (Automobile) while saving the model-specific functionality and information for the child classes. The interface insures that you've got a consistent api when dealing with new objects.

  7. Personally, I'd set up abstract methods in either the parent class (assuming PersonFactory is abstract) or in an implemented interface in order to present a consistent class interface, much like kicken suggested. For instance, if PersonFactory includes

    public abstract function personTypeMethod();
    

    this can be implemented in each of your person type subclasses. Manager can implement it as such

    public function personTypeMethod(){
         return 'I am a Manager! Yay me!';
    }
    

    while Player includes

    public function personTypeMethod(){
         return 'I am a Player! That is awesome!!';
    }
    

    Then your main code simply does something like this

    $my_person= PersonFactory::createPerson($database, $person_id);
    
    // my_person can be an array of objects, getName from parent class valid for all objects
    $details = $my_person[0]->getName();
    
    //run your stuff
    foreach($my_person as $person){
        echo "{$details}: {$person->personTypeMethod()}";
    }
    

    This way your code doesn't care what type of person sub-object it's dealing with, you simply know that you can call personTypeMethod() and get a legitimate and expected response, and you've done away with long or nested conditionals and/or a giant switch() statement.

     

    Obviously, the code above is a mish-mash of stuff and it looks like there'd only be one returned result from PersonFactory::createPerson(), but the thing is you could loop through an array of Person objects this way without having to specify which method you're calling and everything will work, even if you've got 2 players, 3 refs, and 1 manager in the returned array.

  8. Your mysqli_connect() parameters are incorrect. It's

    mysqli_connect({hostname},{username},{password},{databasename});
    

    You're currently skipping the host and adding a table name.

  9. To tell you true, I think you might want to reconsider using the JQueryUI tabs widget using the script bit I posted earlier. On a site I currently maintain, I've got a widget containing between 2 and 14 tabs per each of 51 JQueryUI accordion divs, and it was a snap to set up. But that's neither here nor there, really...

     

    As it stands now, I think your best bet will be to pass the open tab as a GET parameter (or hash, as suggested above), pull the value, loop through all the tabs on the page, run makeInactive() and divHide() on each of them, then run makeActive() and divShow() on the div you pulled from the GET parameter. It's a bit long-winded, I personally think, but it should get the job done with the setup you've got now.

     

    PS - if that's your real database password in the mysqli() instantiation in your sample code, please edit the post to remove it and immediately change that password for your site.

  10. As KevinM1 points out, the first thing you want to do is acquaint yourself with some database theory (nice article, BTW). The table structure you define in your original queries doesn't look bad depending on the content of the 'answers' column in the answers table, but that's outside the scope of this question. Basically, I'd do something along the lines of

    SELECT q.question_id
          ,q.question
          ,a.id AS answer_id
          ,a.answers
    FROM questions q
    LEFT JOIN answers a
        ON q.question_id = a.question_id
    

    If you're feeling real adventurous, you can add an ORDER BY RAND() clause and try to limit the response to one question in order to avoid having to do it in PHP.

    Once you've got your record set returned (for this example, I'm assuming in an associative array called $result), try something along the lines of the following:

    <h2><?php echo $result['question'] ?></h2>
    <input type="hidden" name="question_id" value="<?php echo $result['question_ID']; ?>" id="question<?php echo $result['question_ID']; ?>_id"/>
    <?php
    foreach( $result as $answer ){
        echo "<label for='q{$answer['[answer_id']}'>{$answer['answers']}</label>";
        echo "<input name='answer_{$answer['question_id']}' id='q{$answer['answer_id']}' value='{$answer['answer_id']}' type='radio'/>";
    }
    ?>
    

    As an aside, I wouldn't bother selecting the 'a.correct' column while ouputting the question and answer - you're not going to need that information until you grade the answer (after form submission). Also, I should think it goes without saying, but this won't work if you want to display more than 1 question at a time, but you get the general idea I hope.

  11. I think - and honestly I'm not entirely sure so check the docs - that you can target a specific JQueryUI tab by appending a target anchor to the end of your url. So, if you typically submit to 'myPage.php', try changing it to 'myPage.php#tabUpdate' and that may do what you're looking for. Basically, you can append the ID of the list item and it might do that automatically. If not, it should be easy enough to write out a little script that activates the specified tab on page load.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.