Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter 9'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 4 results

  1. 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)) ) { throw new Exception('e1 An invalid page Id was provided to this page.'); } $_SESSION['id'] = $_GET['id']; // Fetch content from the database: $q = 'SELECT id, title, content, creatorId FROM pages WHERE id=:pageId LIMIT 1'; $stmt = $pdo->prepare($q); $r = $stmt->execute(array(':pageId' => $_GET['id'])); if ($r) { $stmt->setFetchMode(PDO::FETCH_CLASS, 'Page'); $page = $stmt->fetch(); } if (!$page) { throw new Exception ('Failed to retrieve data.'); } } // Catch generic Exceptions: catch (Exception $e) { $pageTitle = 'Error'; include ('includes/header.inc.php'); include ('views/error.html'); include ('includes/footer.inc.php'); } // Create the form: require ('HTML/QuickForm2.php'); $form = new HTML_QuickForm2('editPageForm'); // Add the title field: $title = $form->addElement('text', 'title'); $title->setLabel('Page Title'); $title->addFilter('strip_tags'); $title->addRule('required', 'Please enter page title'); $title->setValue($page->getTitle()); $title->getValue(); // Add the content field: $content = $form->addElement('textarea', 'content'); $content->setLabel('Page Content'); $content->addFilter('trim'); $content->addRule('required', 'Please enter the page cotent'); $content->setValue($page->getContent()); $content->getValue(); // Add the submit button: $submit = $form->addElement('submit', 'submit', array('value' => 'Update This Page')); // Check for a form submission: // Handle the form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Validate the form data: if ($form->validate()) { // Update the database: $q = 'UPDATE pages SET title=:title, content=:content dateUpdated=:date WHERE id=:pageId AND creatorId=:creatorId LIMIT 1'; $stmt = $pdo->prepare($q); $r = $stmt->execute ( array ( ':title' => $title->getValue(), ':content' => $content->getValue(), ':date' => NOW(), ':pageId' => $_GET['id'], ':creatorId' => $user->getId() ) ); // Freeze the form upon success: if ($r) { $form->toggleFrozen(true); $form->removeChild($submit); } } } $pageTitle = 'Edit Page'; include ('includes/header.inc.php'); include ('views/edit_page.html'); include ('includes/footer.inc.php'); ?> This is from post http://larryullman.com/forums/index.php?/topic/1758-chapter-9-exercises/?hl=%2Bedit+%2Bpage. Is this how I should do it? $_SESSION['id'] = $_GET['id']; I get only error when I click the submit button.
  2. Hi, I'm following the cms example (Chapter 9) in the book. On a pc with xampp with windows 7 operating system and I can't figure out why when I load try to get Quickform2 to load on my login.php page I get this error message: Warning:require(classes/PEAR_Error.php): failed to open stream: No such file or directory in C:\xampp\htdocs\site1\includes\utilities.php on line 5 Fatal error: require(): Failed opening required 'classes/PEAR_Error.php' *include_path='.;C:\xampp\php\PEAR;/usr/local/pear/share.pear') in C:\xampp\htdocs\site1\includes\utilities.php on line 5 I may be mistaken but I think that the filepath is incorrect for the php.ini set and that when my utilities.php autoload function searches for the pear classes to load it can't find any. Please help. Thanks, je456
  3. Hi Larry and fellow forum members, I've so far found this forum to be extremely helpful in finding answers to most questions that arises while I'm reading the book. However, as I've just finished reading chapter 9, I'm having some difficulty in understanding the gist of the sub-section called 'Creating Representative URLs'. So, here are my questions : 1) The following is the first script included in this section: var hash = window.location.hash; // Includes the # var content = hash.charAt(1); // Get the second character switch (content) { case 2: // Show tab 2. break; case 3: // Show tab 3. break; case 1: default: // Show tab 1. break; } Then it's followed by the paragraph that says: 'The actual specifics for how you change the content will be explained later in the chapter '. So, can I assume that there are some missing code that should be added within or after the above code in order to change the content (I wonder what these codes are). But what does he mean anyway- to change the content? I thought this section is meant to show us how to create page bookmarks using the window.location.hash property. 2) Then those were immediately followed by: 'For this to work, the JavaScript also has to update the URL when the page’s state changes. Say the setTab() function is called when the user clicks on a tab and it takes the event as an argument: ' function setTab(e) { if (typeof e == ‘undefined’) var e = window.event; } Is that all to it for declaring the setTab() function? I thought it's supposed to contain some onclick event handling code to be declared within the function. If I'm right, what might the code be like? 3) Next comes the following paragraph and one line of code: 'Using the event’s target or srcElement property (depending upon the browser; see Chapter 8), the function would know which tab to show. If the function gets that information and stores it in the tab variable, the JavaScript can then dynamically change the URL accordingly: ' window.location.hash = ‘#’ + tab; Here, I assume that we have to write some code that declare a function that reference the event target and also create a variable named 'tab' that get its value from referencing some HTML elements. But, what should the tab variable reference to? Perhaps the id of the tab that the user click on (which one must procure through the e.target/e.srcElement property). Again, I assume some additional code must be missing. 4) The section ends with: 'And that’s all there is to it (in theory). The user can bookmark the page and return to it in the same state as it was when the user left. Even if the user were to refresh the page, the state would remain the same. ' I could barely grasp the theory at this point. But what I'm more interested in is: how to put them in practical use. Just how one can 'bookmark the page and return to it in the same state as it was when the user left'. How does the complete script for such an application look like? 5) The end of the chapter return to the discussion of the above topic. It shows how to update the hash value as one uses the Back and Forward buttons to navigate. And, these code are provided: var hash = window.location.hash; var hashWatcher = setInterval(function() { if (window.location.hash != hash) { // Changed! updatePage(); }}, 1000); // Every second. Ok, perhaps this part is not difficult to understand. But, still, the whole chapter didn't address the solution (at least not to my satisfaction) to the question of how to share the specific tab information (i.e., browser state) with another person, as it was brought up at the beginning of the section 'Creating Representative URLs'. As no one has mentioned this part of the book in the forum yet, I wonder if I'm the only one to have overlooked something (up to chapter 9) that might help clearing the uncertainties that I have on this topic. Or, perhaps, by charging on with the rest of the book, I would eventually find the solution written somewhere.
  4. Larry, It appears that the URL you used in example 9.1 to get stock market quotes is no longer valid. http://quote.yahoo.c....csv?s=%s&f=nl1 Thank you for your time. -- John.
×
×
  • Create New...