Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I have mine set up like this <?php // DEFINE CONNECTION CREDENTIALS const HOST = 'localhost'; const USERNAME = 'user'; const PASSWORD = 'pwd'; const DBNAME = 'dbname'; // MYSQLI CONNECTION function myConnect($dbname=DBNAME) { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $db = mysqli_connect(HOST,USERNAME,PASSWORD,$dbname); $db->set_charset('utf8'); return $db; } //PDO CONNECTION function pdoConnect($dbname=DBNAME) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } Then if I want a mysqli connection require 'database.php'; $db = myConnect(); and for a PDO connection (strongly recommended) require 'database.php'; $db = pdoConnect();
  2. Tested that with IE, Firefox, Edge and Chrome and that is the case. I'm pretty sure that older IE versions didn't though.
  3. Having read the error message, were you not tempted to read the reference manual for mysqli_query() to see what the correct parameters should be?
  4. Perhaps it's just as well. That would take the relationship to 1-to-many or, potentially, a many-to-many.
  5. But no service record of those replacements - what , where, when ?
  6. No provision in your system then for a motor needing to be replaced?
  7. Simple mathematics is usually reliable.
  8. Correct, but I was trying to illustrate where his method was going wrong by showing how his approach should be used.
  9. Have you considered dividing the number by 100000? var n = 560; n = n / 100000; document.write(n.toFixed(5)); // 0.00560
  10. Simple answer - it's bad design. Database tables are not spreadsheets. To get maximum functionality the tables should be designed using relational design principles, which means they should be normalised. EDIT: Looks like you discovered another basic rule - don't use "select * ", specify the columns you need.
  11. IDs are supposed to be unique identifiers. You have two meals with id = 2. Your items need to be normalised - don't store comma-separated lists.
  12. What happened to the space after the NOT? Date formats are wrong - should be 2019-10-08 and 2019-10-02 In addition the query logic in wrong, - the EXISTS condition will be applied to every row so if such a record exists then no rows will be output. Try... SELECT RentID FROM rental WHERE RentID NOT IN ( SELECT RentID FROM rental WHERE Dispatch <= "2019-10-08" AND Dropoff >= "2019-10-02" ) ; or SELECT a.RentID FROM rental a LEFT JOIN ( SELECT RentID FROM rental WHERE Dispatch <= "2019-10-08" AND Dropoff >= "2019-10-02" ) b USING (RentId) WHERE b.RentID IS NULL
  13. You need a space between NOT and EXISTS
  14. … or in your environment? For example, an upgrade to PHP 7.0+ would cause your script to crumble (mysql_ functions obsolete)
  15. Not just fetch(), there are multiple options open, for example fetch() fetchAll() foreach ($stmt ...)
  16. https://phpdelusions.net/pdo
  17. That is what I would expect. Easily verified with a helper function that returns the php verson.
  18. P.S. ... but not so good with some other languages
  19. Looks like your widget is json encoding the form data - you'll need to decode it to process the contents $pet_data = json_decode($_POST['petlist']['petlist'], true); which should give you ann array like this $pet_data = Array ( [0] => Array ( [Pet Name] => Hal [Pet Type] => Dog [Breed] => Lab [DOB] => 02/10/2013 [Gender] => Male [Special Needs] => No ) [1] => Array ( [Pet Name] => Bill [Pet Type] => Dog [Breed] => Golden [DOB] => 03/20/2015 [Gender] => Male [Special Needs] => No ) ) You will need to reformat your dates before putting into your table (store as yyyy-mm-dd). Why are you adding slashes to all your data? Use prepared queries with mysqli or PDO (preferred). The mysql_ library you are using is obsolete. Why checkboxes for pet type? No one has a pet that is both cat and dog!. Your data column types are overkill. You'll find it more efficient to use INSERT … ON DUPLICATE KEY UPDATE... than your method of checking if it exists then inserting or updating.
  20. On the whole the dimensions returned by imagettfbbox() are pretty accurate. In the image below, the rectangles and baseline position are the dimensions returned by imagettfbbox(). The text then output into the box at the baseline position to check. ("Broadway" font is a couple of pixels out but the rest are spot on) Note that all coordinates returned for the bbox are integers. The code used:
  21. According to your logon code, if the username and password are ok then $_SESSION['login_user'] = $username; // Initializing Session so why are you testing $_SESSION['username'] for 0 or 1.
  22. Set those in your php.ini file, not in the code. If you have any startup errors the code won't execute. If it won't execute it can't set those values. Try changing that to if(!isset($_SESSION['username'] || $_SESSION['username'] =="")){ // To check if the user has logged in Have you checked that the session value is being set on login?
  23. Don't know what you're trying to produce but have you considered SVG instead of bitmapped graphics? They rescale better.
  24. There seems to be some discrepancy with exactly what session variable to check. You need to exit after a redirect to prevent the rest of the code from executing EG In that first line above. Your main problem is trying to use mysql_ functions with v7.0+ (they no longer exist). Had you not turned off the error reporting with error_reporting(0) it might have told you. Use mysqli_ or PDO (better than mysqli). Use prepared queries instead of putting user data directly into the query to prevent SQL injection.
×
×
  • 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.