Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by benanamen

  1. Add 60 days to date <?php $date = new DateTime('2016-09-01'); $date->add(new DateInterval('P60D')); echo $date->format('Y-m-d'); ?>
  2. NO!, You always select the specific column names you want. DO NOT SELECT * Modify this to use the results of your query <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <select name="sort_by"> <option value="">Select Option</option> <?php $array = array('id' => 'ID', 'name' => 'Name', 'amt' => 'Amount', 'status_filter' => 'Status'); foreach ($array as $key => $value) { $selected = isset($_POST['sort_by']) && $_POST['sort_by'] == $key ? 'selected' : ''; echo "<option value='$key' $selected>$value</option>\n"; } ?> </select> <input name="submit" type="submit" value="Submit"> </form> </body> </html>
  3. You are not going to get any help until you make a coherent post that includes a question
  4. Email me. See my Profile. Site wont allow you to get PM's yet.
  5. Forget about ajax. Lookup Mysql CRUD tutorials. You need to learn basic form html first.
  6. Yes. The form values will be available in the POST array. e.g $_POST['first_name']
  7. Your query is not valid. More importantly you are using obsolete mysql code that has been completely removed from Php. You need to use PDO. https://phpdelusions.net/pdo
  8. Forget about making a function, just learn how to use PDO. Start with a basic select. * In practice, you will not be using a variable for the table name. This is a really basic example. <?php $hostdb = 'localhost'; $dbname = 'your_DB'; $username = 'root'; $password = ''; $table = 'YOURTABLE'; $pdo = new PDO("mysql:host=$hostdb;dbname=$dbname", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM $table"; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); echo '<pre>'; print_r($result); echo '</pre>'; ?>
  9. Yeah, but you might as well start using PDO now. Study the link I posted.
  10. You cannot just throw an i onto mysql_* and expect it to magically be mysqli. Start with a basic Mysqli tutorial or better yet, use PDO. https://phpdelusions.net/pdo
  11. Better yet, why dont you tell us what the real problem is that you are trying to solve rather than your attempt at solving it.
  12. I would think that with a unique index, Mysql already knows there is only going to be one result.
  13. You need to stop grabbing stuff off the net. This code is junk. Your time will be better spent to actually learn how to do what you want.
  14. Your code is obsolete, insecure and has been completely removed from Php. It is also vulnerable to SQL Injection. You need to use PDO. https://phpdelusions.net/pdo
  15. You are missing two closing brackets. They open at lines 11 and 32. Use a proper IDE and you won't have these simple problems.
  16. It's not going to work without the opening and closing PHP brackets
  17. Now that you have it working it would be in your "be a better coder" interests to post your "fixed" code. I suspect that although it may work, it is still wrong. We are happy to review what you came up with.
  18. I wasn't trying to be an ***. Programmer's (me included) can be terse in answering. The PDO tutorial link I gave you is very good. You should be able to grasp it fairly easy. We all had to start somewhere. I was basically trying to keep you from wasting your time and provide you the correct direction.
  19. You should have asked your 13 year old. He would have told you that your code is obsolete and has been completely removed from PHP and that your "code" is full of security vulnerabilities. PDO is not a new language. If you took a second to click on the link I provided you would have seen that. You are never going to be a programmer if you get butt hurt when someone tells you the truth.
  20. So much wrong here. The entire code is junk. Toss it and learn PDO. https://phpdelusions.net/pdo
  21. The top is PDO. The bottom is mixed mysql and mysqli. The mysql functions were deprecated over 11 years ago and completely removed in php 7. Do not use Mysql_* no matter what version Php you have. You should be running no less than Php 5.6 at this point. Never ever put variables in your query. You need to use prepared statements. Study this PDO tutorial https://phpdelusions.net/pdo
  22. You are mixing mysql, mysqli and PDO. You need to use all PDO. The mysql_* functions have been completely removed from Php. Also, remove the id from your query,
  23. @Jaques1, thanks for the reminder about PDO. So easy to forget it is actually a Class. Getting back to what I am actually doing as mentioned in other threads, my focus is converting the following minimal login/registration procedural app on my repo to OOP. https://github.com/benanamen/perfect_app This project's sole purpose is for practice and learning OOP. Given what is seen in the repo, where is the first place to start? I assumed it would be database.php or public/registration.php, thus the subjects of my last few threads. This project already contains numerous code recommendations from @Jaques1 from over the last couple years as it has proven out to be the proper way to code. I have pretty much tapped out on procedural improvements so I decide to fork and use it to learn OOP. I have already gone the TWIG templating route although it is not reflected in this repo. I didn't want to clutter the space while learning OOP. Any OOP suggestions or recommendations about anything in the repo are welcome. Like most of you, I am just trying to be a better programmer.
  24. See, that's the problem I keep running into. I don't know enough yet to know if something is wrong. So now, I just spent the last several days trying to learn bad code. I am about ready to just give up on OOP. I have been coding for over 25 years with procedural and have not had any problems with it and any programmer with basic knowledge could jump right in and work on it. I code alone, so any "working on a team" considerations doesnt even matter. Which site is the bad one? Tutorialpoint or the other one? As far as my own projects, I mainly do backend DB apps so starting at the beginning I would need to know how to properly make the DB connection and from there make a query and output the data, let's say starting with a select and tabular records list. I already know to code against an Interface so I can use various DB types. I have read tons of OOP code that does a DB connection. Problem is, I don't know what is right and wrong.
×
×
  • 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.