Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter 1 error view_tasks2.p'.

  • 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 1 result

  1. Hi. I keep getting 1 Notice and 1 Error after I delete all the tasks from the view_tasks2.php in chapter 1 Advanced PHP Object Oriented Programming. Here is the output after I delete all the tasks: Current To-Do List The task(s) have been marked as completed! Check the box next to a task and click "Update" to mark a task as completed (it, and any subtasks, will no longer appear in this list). Notice: Undefined offset: 0 in C:\xampp\htdocs\aqp\chp1\view_tasks2.php on line 83 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\aqp\chp1\view_tasks2.php on line 23 Can someone help me with the errors? here is my code for the view_tasks.php file. It is the exact same code that is provided from the book source code minus my database username, password settings. I have labeled lines 83 and 23 so you can find them easier. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>View Tasks</title> <link rel="stylesheet" href="style.css"> </head> <body> <h2>Current To-Do List</h2> <?php # Script 1.6 - view_tasks2.php /* This page shows all existing tasks. * A recursive function is used to show the * tasks as nested lists, as applicable. * Tasks can now be marked as completed. */ // Function for displaying a list. // Receives one argument: an array. function make_list ($parent) { global $tasks; echo '<ol>'; // Start an ordered list. foreach ($parent as $task_id => $todo) { //line 23 // Start with a checkbox! echo <<<EOT <li><input type="checkbox" name="tasks[$task_id]" value="done"> $todo EOT; // Check for subtasks: if (isset($tasks[$task_id])) { make_list($tasks[$task_id]); } echo '</li>'; // Complete the list item. } // End of FOREACH loop. echo '</ol>'; // Close the ordered list. } // End of make_list() function. // Connect to the database: $dbc = mysqli_connect('localhost', 'root', 'password', 'my_db'); // Check if the form has been submitted: if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['tasks']) && is_array($_POST['tasks']) && !empty($_POST['tasks'])) { // Define the query: $q = 'UPDATE tasks SET date_completed=NOW() WHERE task_id IN ('; // Add each task ID: foreach ($_POST['tasks'] as $task_id => $v) { $q .= $task_id . ', '; } // Complete the query and execute: $q = substr($q, 0, -2) . ')'; $r = mysqli_query($dbc, $q); // Report on the results: if (mysqli_affected_rows($dbc) == count($_POST['tasks'])) { echo '<p>The task(s) have been marked as completed!</p>'; } else { echo '<p>Not all tasks could be marked as completed!</p>'; } } // End of submission IF. // Retrieve all the uncompleted tasks: $q = 'SELECT task_id, parent_id, task FROM tasks WHERE date_completed="0000-00-00 00:00:00" ORDER BY parent_id, date_added ASC'; $r = mysqli_query($dbc, $q); $tasks = array(); while (list($task_id, $parent_id, $task) = mysqli_fetch_array($r, MYSQLI_NUM)) { $tasks[$parent_id][$task_id] = $task; } // Make a form: echo <<<EOT <p>Check the box next to a task and click "Update" to mark a task as completed (it, and any subtasks, will no longer appear in this list).</p> <form action="view_tasks2.php" method="post"> EOT; make_list($tasks[0]); //line 83 // Complete the form: echo <<<EOT <input name="submit" type="submit" value="Update" /> </form> EOT; ?> </body> </html>
×
×
  • Create New...