Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by benanamen

  1. Appreciate the response, but when it comes to OOP I need answers really dumbed down until I get a grasp of this. I want to understand why to do things and not just do it because it works. How does it do that? How do you avoid it? By having the line in question? Would that line generally be public or private? Is it just because you won't get documentation or are their more reasons? Is their any special name for a property with no value like the line mentioned? Lost me here. I looked up code completion and it seems to only apply to IDE's and thus far is the only place I have been aware of it. The rest is russian to me so far.
  2. In the following class, it works with or without line 4 public $num. So why is it there? <?php class mathematics { public $num; public function addTwo() { return $this->num + 2; } } $math = new mathematics; $math->num = 3; echo $math->addTwo(); ?>
  3. So now I have some classes that need to be used by the application. From what I can gather, now I need to know several things to "include" them in the app such as Namespaces, spl_autoload_register, and PSR-4. Could someone please put these things in perspective and when/how to implement. I have read up on each of these items. I am not grasping it as of now. It also seems to be that their is a particular directory structure for the class files and not just a single directory with all the class files in it.
  4. Thanks @Jaques1. I don't know the pros/cons between what you posted and what @kicken posted. Is it an either one will work or is one better than the other for some reason?
  5. Oh, I very much get that. As the link you referenced starts "Our client has come up with the requirement that". As I said, this is just for practicing OOP right now and was old procedural code from long, long ago. The class as you have modified it is very clean now. I will just remove the password storage and it should be good to go. More importantly, I just picked up a couple more tidbits of OOP knowledge which was the purpose of doing this in OOP. Thanks!
  6. Currently it does. It should be logging Bad Username/Bad Password and Valid username/Bad password. I know right now it will also do the undesired bad username/good password which is a fail since a good pass is in plain text. This started from an old procedural login code and right now is just for learning OOP. The idea was to see when a login fails, what was entered when it failed. * Edit: Original code did not log good password in plain text. I see what you did with the PDO type declaration. I never would have got that from the Manual. Does that fall under the self type on the man page linked to? Agree with your class name suggestion I could see that it was near duplicate code and figured that was an area that could be improved. With that said I don't understand how to implement what you just said. I do get the gist of it, but implementing in OOP I am lost at the moment. I still have less than 24 hours into serious OOP study.
  7. I was practicing OOP and made a simple class to log logins. Does anyone see any problems with this or improvements that can be made? Any issue with using NOW() in the query string instead of a placeholder? In another thread, @Jaques1 said: How would I implement that? I rtfm and don't understand it as of yet. <?php // ---------------------------------------------------------------------------- // Database Connection // ---------------------------------------------------------------------------- $dbhost = 'localhost'; $dbname = 'test'; $dbuser = 'root'; $dbpass = ''; $charset = 'utf8'; $dsn = "mysql:host=$dbhost;dbname=$dbname;charset=$charset"; $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO($dsn, $dbuser, $dbpass, $opt); //------------------------------------------------------------------------ // //------------------------------------------------------------------------ $valid_login = new LogLoginStatus($pdo); $valid_login->validLogin('goodusername'); $invalid_login = new LogLoginStatus($pdo); $invalid_login->invalidLogin('bad_username', 'bad_password'); //------------------------------------------------------------------------ // //------------------------------------------------------------------------ class LogLoginStatus { /** * Log Valid/Invalid logins * * @param string login_username * @param string login_password */ public function __construct($pdo) { $this->pdo = $pdo; } function validLogin($username) { $sql = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())"; $stmt = $this->pdo->prepare($sql); $stmt->execute(array( 1, $_SERVER['REMOTE_ADDR'], $username, '***' )); } function invalidLogin($username, $password) { $sql = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())"; $stmt = $this->pdo->prepare($sql); $stmt->execute(array( 0, $_SERVER['REMOTE_ADDR'], $username, $password )); } } ?> CREATE TABLE `user_login` ( `login_id` int(11) NOT NULL AUTO_INCREMENT, `login_status` tinyint(1) DEFAULT NULL, `login_ip` int(10) unsigned DEFAULT NULL, `login_username` varchar(255) DEFAULT NULL, `login_password` varchar(255) DEFAULT NULL, `login_datetime` datetime DEFAULT NULL, PRIMARY KEY (`login_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  8. The OP said PHP magically generates HTML which it does not.
  9. Really? Show me where the html is here: <?= 'Hello World' ?>
  10. When I click the quote icon there is no new line. It is a single line which is how I would expect for it to remain when I click post, but it adds in a line after clicking post. While we are at it. There is another longstanding problem I have had. There is no way for me to add attachments. I can click my media and select something that I somehow was able to attach at one point in time. I can't add anything new.
  11. Didnt fix it. There is no blank line before post is submitted.
  12. Personally, I don't know why the site was "Upgraded". I never had any problems. Only issue I had was the annoying double space when you did a quote.
  13. You are improperly storing the datetime. Format should be YYYY-MM-DD HH:MM:SS
  14. Are you really advocating using the actual word value instead of doing as Psycho suggested " I would have a separate table with the status descriptions". I am sure you must be aware of the numerous issues with using enum.
  15. Depending on the name of a button to be submitted for your script to work will completely fail in certain circumstances. You need to use if ($_SERVER['REQUEST_METHOD'] == 'POST')
  16. Yes and yes. I didn't say yours was wrong. And yes, it is the field name, not the field value which I think is what the OP needs since he uses TD and not TH I use that very type of code on my table row list pages to create dynamic tables. Pulled from one of my pages... foreach ($result as $row) { echo " <tr> \n"; foreach ($row as $name => $value) { echo " <td>$value</td> \n"; } echo " </tr> \n"; }
  17. <table> <?php $row = mysqli_fetch_assoc($result); foreach ($row as $field) { echo "<tr><td>$field['field_name']</td></tr>"; } ?> </table>
  18. You could just search and replace the ( with a ,( which will give you a comma separated list as long as that format is consistent in your data meaning numbers followed by a left ellipses. That would give you 9780735585157,(pbk.;teacher's manual) Then you could do whatever you want with the properly formatted data.
  19. Example: <?php $sql = "SELECT id, name FROM table"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); ?> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <select name="id"> <?php foreach ($result as $row) :?> <option value="<?= $row['id']; ?>"><?= $row['name']; ?></option> <?php endforeach; ?> </select> <button name="submit" class="btn btn-primary">Submit</button> </form>
  20. Why in the world are they having someone with no experience build an application? That's because they know even less than you do. In that format you can pretty much end up with any output you want. Since you have no experience, it is probably not something you should be attempting for use in a real business scenario. I could not PM you. I am available for hire.
  21. How about it OP? What exactly do you have going on?
×
×
  • 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.