Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About alex_r

  • Rank
  1. I've got it working now . (After a few changes) However I've some other question now: 1. Is doing something like this OK/good practice? Specially the elseif block (for SessionID) which does nothing if validated? if (isset($_GET['id'])) { if (filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $_SESSION['id'] = $_GET['id']; } } elseif ( isset($_SESSION['id']) || filter_var($_SESSION['id'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { ; } else { th
  2. I get this error message: "e1 An invalid page Id was provided to this page." which is in this code (above) throw new Exception('e1 An invalid page Id was provided to this page.'); under Validate page Id block.
  3. Here is my code which I've written to make the 'edit_page', but am unable to update the database. Please, anyone, take a look and help me out by pointing out my mistakes and how to rectify them. Also some pointers to improve code/coding skills would be really appreciated. Thanks in advance. <?php # Script 9.17 - edit_page.php // This page both displays and handles the "Edit" page. require ('includes/utilities.inc.php'); try { // Validate page Id if ( !isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1)) )
  4. Am not sure if my understanding of the concept is correct, so I'd appreciate any input to help me with it. set_include_path(get_include_path() . PATH_SEPARATOR . $path); This line tells PHP to first search for the included file (in this Script "require('HTML/QuickForm2.php');") in the path returned by "get_included_path()". If the file is not found there, then PHP will look for the file in "$path". Have I got it right?
  5. $path = '/usr/local/pear/share/pear/'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); What does this line do? PHP documentation explains it as extending the include path. echo outputs : .:/opt/lampp/bin/php:/usr/local/pear/share/pear/ Can someone please break down the concept for me? Also login seems to work when even if I do this: (path where QuickForm2 is installed for my setup: Ubuntu 16.10 xampp-5.6.30-0) $path = '/opt/lampp/lib/php/HTML/';
  6. Am not sure what happened too. I tested using "include", which worked and later i used "require" and now seems to work fine no problem. I don't know what the problem is. // Load the class definitions /* include('Shape.php'); include('Triangle.php'); */ require('Shape.php'); require('Triangle.php');
  7. http://stackoverflow.com/questions/9882145/the-best-way-to-include-a-file-across-multiple-files-in-php-for-inheritance -- The selected answer to this question (answered by deceze) answers this, I think?
  8. abstract class Shape { // No attributes to declare // No constructor or destructor defined here // Method to calculate and return the area. abstract protected function getArea(); // Method to calculate and return the perimeter. abstract protected function getPerimeter(); } // End of Shape class. Next I declared "Triangle" class <?php class Triangle extends Shape { // Declare the attributes: private $_sides = array(); ... Then created the "abstract.php" <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Triangle</tit
  9. Thanks Larry. That point is clear. However this is not clear: Using the same array, but passing comp2() function as the second argument in uasort the result is inverted. The difference between comp1() and comp2() function is the difference in the position of arguments. The two function does the same comparison operation i.e $x < $y Maybe am missing something about using comparison operaiton inside 'return' or the way variables behave inside a function with respect to the arguments listed while defining function?
  10. I've just started this book and am really confused with an expression. Can somebody please explain the mechanism behind the expression, given below, used in Script 1.1 - sort.php return ($x < $y) // Creating an array $a = [1, 5]; // creating comparison function using the above expression function comp1($x, $y) { return ($x < $y); } // using uasort() uasort($a, 'comp1'); // output the result echo '<pre>' . print_r($a, 1) . '</pre>'; // creating the same function as above but interchanging the arguments position function comp2($y, $x) { return ($x < $y); } //
  11. Hi, phpadawan Just checking in to see if you've solved the issue. The above post from admin (#4) is actually from me. (Sorry I had to do that, had issues with replying). Anyway I solved after about 3-4 weeks when I revisited my code. I had this habit of starting the php opening tag after a tab (4 spaces on my system) in the text editor. But now I've learned (the hard way, despite the many warnings in the book) that, that was the cause of the underlying issue. Removed the indentation, and problem solved. You might not have made the same error as mine but it's worth a shot. Thanks alot La
  • Create New...