Jump to content

maxxd

Gurus
  • Posts

    1,698
  • Joined

  • Last visited

  • Days Won

    53

Everything posted by maxxd

  1. 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.
  2. It's the joy of PHP's not being a strongly-typed language. Any property or variable can hold any kind of data at any time. I agree with Jacques1 that it's better to be explicit and define the type before assigning values.
  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. if(strlen($postcode) > 5){ $postcode_wc = substr($postcode,0,-3); } Give that a shot.
  5. KevinM1 - that's how I always thought about it, but I haven't had nearly enough coffee today. Thanks for the detailed explanation!
  6. 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.
  7. 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.
  8. Try this in your script print("<pre>".print_r($products,true)."</pre>"); and post the output here.
  9. 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.
  10. 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.
  11. The problem is that the POST variables are still set. You'll need to redirect the browser after a successful CRUD operation. You can simply reload the current page or redirect to a new page, whichever is best for your situation. There's actually a name for this operational method, but I can't for the life of me remember what it is right now...
  12. Sorry for the vast amounts of technobabble, but glad you got it working! You'll want to mark this thread resolved and start a new one for the other issue - post your code there and we'll see what's up.
  13. If the address is spelled correctly and you're still getting redirected, the DNS hasn't resolved. Try accessing the site by IP instead.
  14. Are you developing locally or on a remote server? If you're local, you'll more than likely enter 'http://localhost/path/to/site' in the browser's location bar. If remote, make sure you're spelling the site address correctly.
  15. 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.
  16. 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.
  17. Wow. Somehow, through all of this, I read that it was a JQueryUI tabs widget. Literally the entire time. Perhaps I've got more going on today at work than I thought I did...
  18. Correct - put it between the $(function(){ and }); lines that surround the $( "#datepicker" ).datepicker(); line. Again, I make no guarantee about cut-n-paste functionality, but it's a place to start.
  19. Try this (no guarantees, mind you...) var curTab = window.location.hash; if( curTab !== '' ){ $('#simple-tabs').tabs( { active: curTab }); } By the way, you can use one set of <script> tags to define all your javascript functions.
  20. 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.
  21. 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.
  22. Couple things here. First, I may be missing it but I'm not seeing where you're setting the $answers variable. Or the $question variable, for that matter - are you not showing some looping? In addition, if your script is giving you anything other than an array to string conversion error, you're printing the same string ($answers) over and over again. Your initial queries could be rewritten using a join to be a single call to the database as well. There are a couple different ways to get one random question and it's associated answers without having to load the entire contents of both tables into an array.
  23. Ah - remove the '$' in front of the array() keyword. In other words, instead of $arr = $array('email'=>$email); use $arr = array('email'=>$email);
  24. What does ArrayBinder() look like? Everything looks ok (please use the code tags in the future - they make your code much easier to read) at first glance. Usually the error message will give you a line number and file name. That'll help you pin down where the actual problem is happening.
  25. You've got 8 columns listed, and only 7 values - looks like confirmusername.
×
×
  • 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.