Jump to content
Larry Ullman's Book Forums

Leaderboard

Popular Content

Showing content with the highest reputation since 03/08/20 in Posts

  1. Hi All, Here is my solution to Pursue exercises in CH3. I combined 4 questions into one script. If you could take a look at my code and correct if I am wrong, I would be reaaaaly appreciated! Here are the questions on the book: # 1. Change calculator.php so that it uses a constant in lieu of the hard-coded average speed of 65. # 2. Better yet, modify calculator.php so that the user can enter the average speed or select it from a list # of options. # 3. Update the output of calculator.php so that it displays the number of days and hours the trip will take, when the number of hours is g
    1 point
  2. I'm not sure I follow exactly what you're asking but I'll try to answer as best as I can... First, a constant would be better than using a hardcoded number--65--that has no context and can easily be lost within the code. The constant allows you to "label" the value and makes it easier and more obvious to change down the line. Second, the next prompt suggests taking the average speed as user input instead of using the hardcoded number or a constant. So you'd just repeat what the calculator does with distance but for the average speed.
    1 point
  3. Ah, no, you can't do that. You'll need to use PHP to break the multiple selections into their single counterparts and insert each one separately.
    1 point
  4. Thanks for the question! I'm not terribly worried about this. Microsoft said they're not going to provide builds of PHP for Windows anymore. Certainly someone else will pick up the torch. Also, to me, this is more of an issue for people learning or developing on Windows. I don't have hard numbers but I assume the vast majority of servers using PHP are running Linux.
    1 point
  5. Yes, both versions are comparable with respect to validating the gender. To use the NULL coalescing operator in Script 2.4, you'd probably just write it like your version of Script 2.3 (note that you don't need the $gender = NULL in there though).
    1 point
  6. I wouldn't say that line is necessary. The $gender variable is already assigned a value before being used so assigning it a "false" value has no impact.
    1 point
  7. Thanks for the interest in more books! Much appreciated! The "PHP Advanced" book would be the logical one after "PHP & MySQL". Or the e-commerce book that Necuima recommended.
    1 point
  8. Re reading a PDF - you could have a look at: https://www.pdfparser.org/ but I have not used it. Cheers
    1 point
  9. Hi Jai, Mr Ullman has a great book on e-commerce - "Effortless E-Commerce" - 2nd edition with PHP and MySQL. Cheers
    1 point
  10. Ok, the following is how I send emails from PHP. Uses PHPMailer. In XAMPP you need to tell it where your normal email connection is. $host = substr($_SERVER['HTTP_HOST'], 0, 5); if (in_array($host, array('127.0', '192.1', 'local'))) { $local = TRUE; // echo "Local is true, HOST is $host"; } else { $local = FALSE; // echo "Local is false, HOST is $host"; } if ($local) { // tests for using XAMPP locally ini_set('sendmail_from', 'your email address'); // needed for Win 10 localhost (Development) ini_set('SMTP', 'your email service SMTP server'); // needed for Win
    1 point
  11. Hey Jan, Thanks for the question and for the nice words! There's really no "X hours" that apply here, as every person is different. But the "how" is really very simple and reliable across the board: 1. Find a resource to learn from (e.g., my books!). 2. Take notes as you read. 3. Try. Try. Try. It's a known thing about the mind that you'll learn better if you take notes, even if you don't ever refer to them. Not just highlight, but actually write down key thoughts somewhere. And if you refer to them later, all the better. But, no matter how much you read--either in time or n
    1 point
  12. Thanks Larry, I got it; that way these two variables $days and $days_modulus: $days = $hours / 24; $days_modulus = $days % 24; are not needed, which makes the code concise. I moved them into the 'else' conditional: } else { // $hours > 24 echo '<h1>Total Estimated Cost</h1> <p>The total cost of driving ' . $_POST['distance'] . ' miles, averaging ' . $_POST['efficiency'] . ' miles per gallon, and paying an average of $' . $_POST['gallon_price'] . ' per gallon, is $' . $cost . '. If you drive at an average of ' . $_POST['a
    1 point
×
×
  • Create New...