Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 01/16/2019 in all areas

  1. 1 point
    Your instructor is an idiot. That code has no business being given to anyone learning PHP. Try not to learn too much from it. The principle behind binding parameters is that you write the overall structure of the query without any data inside it, then tell MySQL that certain locations within it (like those marked with ?s) correspond to certain values (the bound parameters). The idea is that you can't accidentally confuse syntax with data. Problem with this code is that it isn't so much "accidentally confusing syntax with data" as it is intentionally confusing syntax with data. Which is terrible, and why you should try to ignore it as much as possible and focus on the basic concepts of prepared statements.
  2. 1 point
    Yes - our reading comprehension is quite adequate. But perhaps you understanding of what MySQL does for you and what HTML does needs some understanding. As Barand has shown you, a query gathers the data and the HTML will then format its usage as you desire. PS - You find PDO to be 'too abbreviated' for you? I've not heard of that as an excuse ever. Simple is usually the better choice for anything IMHO. I think perhaps you had your own trouble with "are-read with comprehension " and a little more reading would help you adopt the use of PDO over any other database interface that your PHP install offers.
  3. 1 point
    I would suggest you take this a step at a time. Start with the database. When you have the DB done, show us what you did and we will review it and guide you to any changes/improvements. After you implement the final DB design then we can move to the next step. You already have the overall summary of the project which was the first step. * Just a heads up. You would not have an "age" column. You would store the birth date and calculate the age from that.
  4. 1 point
    There won't be any "affected rows". It is not an update, delete or insert query.
  5. 1 point
    Oh yes it will try { $db->exec("INSERT INTO units(id, unit) VALUES (1, 'Test')"); // deliberate duplicate } catch (PDOException $e) { echo '<pre>', print_r($e->errorInfo, 1), '</pre>'; } Outputs Array ( [0] => 23000 [1] => 1062 [2] => Duplicate entry '1' for key 'PRIMARY' )
  6. 1 point
    I don't understand what you are looking for. What "content" do you want? Are you asking how to handle the error? If so, you can try/catch the error and respond the way you want. From the manual Source: http://php.net/manual/en/pdo.errorcode.php
  7. 1 point
    Almost - you are binding to :user_id when you used :name in the query. You could speed it up significantly by doing a multiple insert EG $params = []; $data = []; for($i = 1; $i <= $entries; $i++) { $params[] = '(?,?)'; array_push($data, $id, $name); } $stmt = $db->prepare("INSERT INTO entries(id, name) VALUES " . join(',', $params));; $stmt->execute($data); which creates a query in the form INSERT INTO entries (id, name) VALUES (55, 'Smith'), (55, 'Smith'), (55, 'Smith'), ... , (55, 'Smith'); Timings: Yours : 0.3336 seconds Mine : 0.0591 seconds (5.6x faster) With hundreds of records it could be up to 50 or 60 times faster.
  8. 1 point
    Create a function that looks for inputs with a specific attribute and then apply your date picker code to those. For example: jQuery(function($){ var defaultSettings = { format: 'yyyy/mm/dd', calendarWeeks: true, weekStart: 1, todayHighlight: true }; $('[data-datepicker]').each(function(){ var $input = $(this); var settings = $.extend($input.data('datepicker')||{}, defaultSettings); $input.datepicker(settings); }); }); Then in your HTML you just give your inputs the appropriate attribute. If you want to change the default settings, put the new settings as the attributes value. <input type="text" name="start" data-datepicker> <input type="text" name="end" data-datepicker> <input type="text" name="birthday" data-datepicker='{"format":"mm/dd/yyyy"}'>
This leaderboard is set to New York/GMT-05:00
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

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.