Jump to content

Search the Community

Showing results for tags '$_server'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. I have this function that creates breadcrumbs from the URL It appears to work but i get these error messages Line 13 points to $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; and line 16 is $last = end(array_keys($path)); Any ideas how i can remove these errors/warnings? here is the code public function breadcrumbs ($separator = ' ยป ', $home = 'Home') { $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; $breadcrumbs = array("<a href=\"$base_url\">$home</a>"); $last = end(array_keys($path)); foreach ($path AS $x => $crumb) { $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb)); if ($x != $last){ $breadcrumbs[] = '<a href="'.$base_url.'/'.$crumb.'">'.$title.'</a>'; }else{ $breadcrumbs[] = $title; } } return implode($separator, $breadcrumbs); }
  2. I've been trying to improve my php skills by reading and going through the examples (step by step in order) from the book "PHP Advanced and Object-Oriented Programming". I'll try to explain it the best that I can the problem I have followed with some code. I think I'll will start with code: I have to grab the data for after all it's an edit page: <?php # edit_page // This page both displays and handles the "edit the page" form. // Need the utilities file: require('includes/utilities.inc.php'); try { // Validate the page ID: if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { throw new Exception('An invalid page ID was provided to this page.'); } // Fetch the page from the database: $query = 'SELECT id, title, content, DATE_FORMAT(dateUpdated, "%e %M %Y") as dateUpdated FROM pages WHERE id=:id'; $stmt = $pdo->prepare($query); $result = $stmt->execute(array(':id' => $_GET['id'])); // If the query ran OK, fetch the record into an object: if($result) { $stmt->setFetchMode(PDO::FETCH_CLASS, 'Page'); $page = $stmt->fetch(); } else { throw new Exception('An invalid page ID was provided to this page'); } } catch(Exception $e) { // catch generic Exceptions $pageTitle = 'Error!'; include('includes/header.inc.php'); include('views/error.html'); } Then I have to setup my Quickform2 form // Creat a new QuickForm2 form: // set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/local/pear/share/pear/'); 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 a page title'); // Add the content field: $content = $form->addElement('textarea', 'content'); $content->setLabel('Page Content'); $content->addFilter('strip_tags'); $content->addFilter('trim'); //$content->addRule('required', 'Please enter the page content'); // Set defaults for the form elements $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array( 'title' => $page->getTitle(), 'content' => $page->getContent() ))); // Add the submit button: $submit = $form->addElement('submit', 'submit', array('value' => 'Edit This Page')); and then I have to validate and submit the edited data to the database (This is where I run into problems) // Check for a form submission: if (!isset($_SERVER) && $_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form submission // Validate the form data: if ($form->validate()) { $query = 'UPDATE pages SET creatorId=:creatorId, title=:title, content=:content, dateUpdated=NOW() WHERE id=:id'; // Insert into the database: //$query = 'INSERT INTO pages (creatorId, title, content, dateAdded) VALUES (:creatorId, :title, :content, NOW())'; $stmt = $pdo->prepare($query); $result = $stmt->execute(array(':creatorId' => $user->getId(), ':title' => $title->getValue(), ':content' => $content->getValue(), ':id' => $page->getId())); // Freeze the form upon success: if ($result) { $form->toggleFrozen(true); $form->removeChild($submit); } } // End of form validation IF. } // End of form submission IF. This is the error it gives: Details (not for public consumption): An invalid page ID was provided to this page. Notice: Undefined variable: page in C:\xampp\htdocs\php_test\chapter-09-CMS-with-OOP\edit_page.php on line 56 Fatal error: Call to a member function getTitle() on a non-object in C:\xampp\htdocs\php_test\chapter-09-CMS-with-OOP\edit_page.php on line 56 I think it might have something to do with the url being different (edit_page.php?id=5) vs (edit_page.php) when it kicks out the error. I don't know if I have my query right or the POST right or what have you. This is the first time I really have been using PDO for previously I've been using mysqli to go back and forth to the MySQL database. I believe I have it right? Anyways, I apologize if I didn't make myself clear and I can always reply with more information if needed. I have gone to the author's forums, check the Quckform2 documentation, php.net manual and have done a bunch of Google searches to no avail to fix the problem. Well at least I know now how to catch an error, but now the thing is how to fix them. Thanks, John
×
×
  • 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.