Book Image

Sphinx Search Beginner's Guide

By : Abbas Ali
Book Image

Sphinx Search Beginner's Guide

By: Abbas Ali

Overview of this book

Table of Contents (15 chapters)
Sphinx Search
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Time for action - adding code to save feed


  1. 1. Add the code to save form data in /path/to/webroot/feeds/add.php as shown in the following highlighted code:

    <?php
    /**
    * File: /path/to/webroot/feeds/add.php
    */
    include('init.php');
    // If we have data in POST then get it from there else initialize
    // to empty strings
    $viewVars['name'] = !empty($_POST['name']) ? $_POST['name'] : '';
    $viewVars['url'] = !empty($_POST['url']) ? $_POST['url'] : '';
    // Check if form is submitted and if we have a feed name and url
    // then save the data
    if (!empty($_POST['name']) && !empty($_POST['url'])) {
    // First check if the feed being added is already in our database
    $stmt = $dbh->prepare("SELECT id FROM feeds WHERE url = :url");
    $stmt->bindParam(':url', strip_tags(
    $viewVars['url']),
    PDO::PARAM_STR);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    // If this is not a duplicate item then only add it
    if (empty($result)) {
    $stmt = $dbh->prepare("INSERT INTO feeds SET name = ...