Saturday 28 December 2013

PHP MySQL Simple Delete using PDO in Bootstrap Tutorial

 Furqan Aziz |  28 Dec 2013 |  Tutorials
IntroductionPHP MySQL Simple Delete using PDO in Bootstrap Tutorial
Delete Statement is very common and used to Delete existing records in database table.PHP MySQL Simple Delete using PDO in Bootstrap is a tutorial in which we will learn how to delete data in database table using PDO (PHP Data Objects) prepared statements while using Bootstrap CSS Framework. We will create table fist and then insert some records in it, then we will create a form for delete. Then we will use Post method in form to send values to another page and then we will get values, bind them and use them in prepare statements. Finally we will show the success message if data Deleted successfully. This tutorial contains demo and source in which you can test INSERT, UPDATE and SELECT options at one place. We will learn
  • How to create a fruit list table for demo.
  • How to make a Connection Page.
  • How to prepare query for delete
  • How to bind values for query.
  • How to execute delete query.
  • How to show a success message for Delete.

Source Files and Folders Explanation

Source Code Folder contains many files and folders, below is the explanation of each files and folders.
  • sql.txt contains full database structure along with sample data.
  • index.php is a startup page which contains try it button.
  • AdminIndex.php is a page which has various options like INSERT, UPDATE, DELETE, SELECT buttons along with tables for showing data.
  • FruitDMy.php is about prepared query for Delete functionality.
  • configPDO.php is a file which will create connection with MySQL database.
  • footer.php is a file which contains footer bar and form for Fruit name delete.
  • assets folder contains necessary css files, icons, images and js files.

    Create Table and Sample Data

  1. We will create sample table in our database using sql.txt file which contains following table create queries and sample data for demo and test.
    • fruitsratelist table contains fields like Fruitname and its Rate.
    • CREATE TABLE IF NOT EXISTS `fruitsratelist` (
        `Fruitname` varchar(15) NOT NULL,
        `Rate` double NOT NULL
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    • INSERT INTO `fruitsratelist` (`Fruitname`, `Rate`) VALUES
      ('Apple', 70),
      ('Apple', 90),
      ('Mango', 60),
      ('Banana', 70),
      ('Strawberry', 80),
      ('Apple', 40),
      ('Lemon', 70),
      ('Kiwi', 80);

    Create Delete Button

  2. We will create a button for DELETE inside option side nav in AdminIndex.php page with id deleteit and set data-toggle as modal for showing reference DIV in a modal. We set button class as danger button.
    • <a href="#deleteit" data-toggle="modal" class="btn btn-danger">Delete</a>
      

    Create Form in Modal

  3. Modal will be open when Delete Button pressed which will display below form for Delete of Fruit Names. Form code is in footer.php page which is included in AdminIndex.php. This form contains fruit names in drop down select option for delete. When we press Delete Fruit Records Button it will send values as POST method to FruitDMy.php.
    • <div id="deleteit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3 id="myModalLabel">Delete Fruit Name and Rates</h3>
      </div>
      <div class="modal-body">
      <form class="form-horizontal" method="post" action="FruitDMy.php">
      
      <div class="control-group">
      <label class="control-label" for="Fruitname1">Fruit Name</label>
      <div class="controls">
      <select name="Fruitname1" id="Fruitname1"  required="required">
      <option value="">Fruit Name</option>
      <?php
      include("configPDO.php");
      // We Will prepare SQL Query
      $STM = $dbh->prepare("SELECT DISTINCT  Fruitname FROM fruitsratelist");
      // bind parameters, Named parameters always start with colon(:)
      $STM->execute();
      // we will fetch records like this and use foreach loop to show multiple Results
      $STMrecords = $STM->fetchAll();
      foreach($STMrecords as $row)
      {
      echo"<option value='$row[0]'>$row[0]</option>"; 
      }      
      ?> 
      </select>
      
      </div>
      </div>
              
      
      <div class="control-group">
      <div class="controls">
      <input type="submit" name="submit" id="submit" class="btn btn-danger" value="Delete Fruit Records">
      </div>
      </div>
      </form>
      
      </div>
      </div>  
      

    Connect to Database

  4. configPDO.php file use a PDO (PHP Data Objects) for connecting MySQL Database.
    • <?php
      // mysql hostname
      $hostname = 'localhost';
      // mysql username
      $username = 'root';
      // mysql password
      $password = '';
      // Database Connection using PDO
      try {
      $dbh = new PDO("mysql:host=$hostname;dbname=YourDatabaseName", $username, $password);
          }
      catch(PDOException $e)
          {
          echo $e->getMessage();
          }
      ?>

    Prepare and Execute Delete Queries

  5. Now we will discuss our FruitDMy.php which is used for getting values from the form and then Delete these in database using PDO query.
    • <?php
      include('configPDO.php');
      if(isset($_POST["submit"])=="Delete Fruit Records")
      
      {
      // Define Variable
      $Fruitname1    =  $_POST[Fruitname1];     //Fruitname1
      
      // We Will prepare SQL Query
       $STM = $dbh->prepare("DELETE FROM fruitsratelist  WHERE Fruitname=:Fruitname1");
      // bind paramenters, Named paramenters alaways start with colon(:)
          $STM->bindParam(':Fruitname1', $Fruitname1);
      // For Executing prepared statement we will use below function
          $STM->execute(); 
      // We use header here for redirecting it to other page where we will show success message.    
      header( "location:AdminIndex.php?Fruitstatsdeleted=77083368");             
      }
      ?> 

    Prepared Queries Methods

    There are three various methods to write PDO queries.
    • In this Demo we used named parameters key with prepared statement. Binding parameter is must before execution using this method.
      • $STM = $dbh->prepare("DELETE FROM fruitsratelist  WHERE Fruitname=:Fruitname1");
        $STM->bindParam(':Fruitname1', $Fruitname1);
        $STM->execute();
        
      OR
    • Other method is to use unnamed parameters with question mark (?)
      • $STM = $dbh->prepare("DELETE FROM fruitsratelist  WHERE Fruitname=?");
        $STM->bindParam(1, $Fruitname1);
        $STM->execute();
        
      OR
    • Below method is without binding and it can make code ripe for SQL Injections.
      • $STM = $dbh->prepare("DELETE FROM fruitsratelist  WHERE Fruitname=$Fruitname1");
        $STM->execute();
        
    • For Getting how many records Deleted we can use rowcount() function.
      • $Records_Deleted= $STM->rowCount();
        

    Show Success Message

  6. After data Deleted We will redirected to Adminindex.php page where we will show success message using codes return from FruitDMy.php
    • if($_GET["Fruitstatsdeleted"]==77083368)  
      {
      echo "<div class='alert alert-error'>"; 
      echo "<button type='button' class='close' data-dismiss='alert'>×</button>"; 
      echo "<h4>Updated.</h4>"; 
      echo "Fruit Name and all it rates deleted from this Demo System."; 
      echo "</div>";
      }

    Tools Required

    We used following tools and technologies for developing PHP Simple Delete using PDO in Bootstrap Tutorial.
    • PHP as Server Side Scripting Language
    • MySQL as a Database.
    • Bootstrap as CSS Framework.
    • JQuery as a service.
    • jqBootstrapValidation for validating sign-in form.
    • phpMyAdmin for creating database and tables.
    • Sublime Text 2+ as a code editor.
    • XAMPP as a package for Apache web server, PHP and MySQL.
    • Google Chrome as a browser for testing.
    Thanks for reading. Enjoy and share with friends.

Conclusion

We hope you will like PHP Simple Delete using PDO in Bootstrap Tutorial and find it easy. We used latest PDO (PHP Data Objects) Prepared statements in this tutorial with Bootstrap CSS Framework for making this quickly. For any query/suggestions please send message on ourFacebook Page.

Sunday 22 December 2013

Top PHP Framework Collection


Introduction

PHP Framework helps developers to create applications with speed and ease. Choosing best framework is very important for the successful development of the projects. A good PHP Framework must have following features
  • Must be compatible with latest PHP Version.
  • Must support MVC Structure.
  • Must support Multiple Databases.
  • Must has inbuilt template engine.
  • Must support caching and Validation.
  • Must support Ajax and useful modules.
Please Click here to see Details

Framework Collection and Features

Below is the collection of best PHP Frameworks for PHP developers.

Yii Framework

Yii is a high-performance PHP framework best for developing Web 2.0 applications. Yii helps Web developers build complex applications and deliver them on-time.
  • It's works efficiently with AJAX. It includes input validation, output filtering, SQL injection and Cross-site scripting prevention.
  • It's follows the MVC pattern, ensuring a clear separation of logic and presentation.
  • It's implement a skinning and theming mechanism that allows you to quickly switch the outlook of a Yii-power website.
  • Errors are handled and presented more nicely, and log messages can be categorized, filtered and routed to different destinations.
  • Every single method or property is clearly documented.
  • It's provide a set of intuitive and highly extensible code generation tools that can help you quickly generate the code you need for features such as form input, CRUD.
Yii Framework

CodeIgniter Framework

A Fully Baked PHP Framework. CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you're a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you're tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.
  • a framework with a small footprint and exceptional performance.
  • It has clear, thorough documentation.
  • A framework with nearly zero configuration provide simple solutions to complexity
CodeIgniter Framework

CakePHP Framework

CakePHP makes building web applications simpler, faster and require less code.
  • Use code generation and scaffolding features to rapidly build prototypes.
  • No complicated XML or YAML files. Just setup your database and you're ready to bake.
  • The things you need are built-in. Translations, database access, caching, validation, authentication, and much more are all built into one of the original PHP MVC frameworks.
  • Instead of having to plan where things go, CakePHP comes with a set of conventions to guide you in developing your application.
  • It comes with built-in tools for input validation, CSRF protection, Form tampering protection, SQL injection prevention, and XSS prevention, helping you keep your application safe & secure.
CakePHP  Framework

Symfony Framework

Symfony is a PHP framework for web projects. Speed up the creation and maintenance of your PHP web applications. Replace the repetitive coding tasks by power, control and pleasure.
  • Easy to install and configure on most platforms with independent Database engine.
  • Simple to use and compliant with most web best practices and design patterns.
  • Easy to extend, allowing for integration with other vendor libraries.
Symfony Framework

Zend Framework

Zend Framework 2 is an open source framework for developing web applications and services using PHP 5.3+. Zend Framework 2 uses 100% object-oriented code and utilises most of the new features of PHP 5.3.
  • Building blocks that can be used piece by piece with other applications or frameworks.
  • All the cryptographic and secure coding tools you need to do things right.
  • Easy to adapt the framework to your needs.
  • A vibrant and active contributor and user base for getting help and giving back.
  • Engineered with performance tuning in mind.
  • A proven history of success running business critical and high-usage applications.
Zend Framework

Laravel Framework

The php framework for web artisans. Your life as a developer just got a whole lot easier.
  • Use simple Closures to respond to requests to your application. It couldn't be easier to get started building amazing applications.
  • Ships with the amazing Eloquent ORM and a great migration system. Works great on MySQL, Postgres, SQL Server, and SQLite.
  • Use native PHP or the light-weight Blade templating engine. Blade provides great template inheritance and is blazing fast. You'll love it.
  • Build huge enterprise applications, or simple JSON APIs. Write powerful controllers, or slim RESTful routes. Laravel is perfect for jobs of all sizes.
Laravel Framework

FuelPHP Framework

FuelPHP is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks, with a fresh start!
  • It is a MVC (Model-View-Controller) framework that was designed from the ground up to have full support for HMVC as part of its architecture.
  • It also supports a more router based approach where you might route directly to a closure which deals with the input uri, making the closure the controller and giving it control of further execution.
  • Security concerns have been front and center from the beginning. Out-of-the-box FuelPHP's Views will encode all your output to make it secure and prevent XSS attacks.
FuelPHP Framework

Conclusion

Now finally you have to choose the best framework which is suitable for your project. Hope you like this collection and find it very useful for choosing best PHP Framework for Development. For any query/suggestions please send message on our Facebook Page.Thanks :)

Monday 9 December 2013

Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial

Convert Simple Text To 3D Text using Adobe Fireworks CS6
Source : Click Here 
Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial is a tutorial which will guide how to create a 3D text in just simple and easy steps. We used Pointer Tool, Text Tool, Skew Tool, Properties and various Filters to make the text 3D and cool.
We will learn
  • How to make a 3D Text from simple text.
  1. Open Adobe Fireworks, click on File, choose New (CTRL + N), Set following values and Press OK.
    • Width equal to 750 Pixels.
    • Height equal to 500 Pixels.
    • Resolution equal to 72 Pixels/Inch.
    • Canvas Color as Transparent.
    Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  2. Now write some sample text on Canvas using Text Tool (T) and Set font size as 200 Pixels, choose any color you like and make it Bold.
  3. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  4. Now Select the text with Pointer Tool (V) and choose Skew Tool (Q) and Grab the left corner and increase it 50%. It will look like below.
  5. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  6. We will use Solid Shadow and Inner Shadow on this text. So Right Click on the text and choose Convert to Paths (CTRL + SHIFT + P).
  7. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  8. Now Right Click on the Text and Choose Ungroup (CTRL + SHIFT + G), choose all the Paths and Set 2 Pixels White (#FFFFFF) stroke line.
  9. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  10. Now Click on Filters (+), Choose Shadow and Glow, Click on Solid Shadow, Set following values and Press Ok.
    • Angle equal to 270 Degree.
    • Distance equal to 20.
    • Solid Color Yes and choose color as #F0F0E1.
    Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  11. Now again Click on Filters (+), Choose Shadow and Glow, Click on Inner Shadow, Set following values and Press Ok.
    • Distance equal to 15.
    • Opacity equal to 25.
    • Softness equal to 25.
    • Angle equal to 90.
    • Knock Out as unchecked.
    • Color equal to#000000.
    Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  12. Now Select full text and Right Click on it and Choose Edit and Select Clone (CTRL + SHIFT + D). It will create duplicate copy of text, Press (CTRL + DOWN ARROW) to send it Backward and do following
    • Select Solid Shadow and Click on (-) To Remove it.
    • Select Inner Shadow and Click on (-) To Remove it
    • Color equal to#000000.
    • Filter Click, Choose Blur, Select Gaussian blur, Set Values to 8.4 and Press Ok.
    Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  13. Now Adjust Gaussian Blur text below the 3d text like below.
  14. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
  15. Below is the final preview of the 3D Text.
  16. Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
    We used following tools for making 3D Text.
    • Adobe Fireworks CS6 as a Graphics designing Tool.
    • Google Chrome as a browser for showing images.
    Thanks for reading. Enjoy and share with friends.
We hope you will like Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorialand find it easy. We will share other Fireworks tutorials with you soon. For any query/suggestions please send message on our Facebook Page.