By : Ashish Modi. CRUD USING PHP (Create, Read, Update and Delete on Database) Create Database and Table using following Sql Syntax.



Similar documents
A table is a collection of related data entries and it consists of columns and rows.

CS412 Interactive Lab Creating a Simple Web Form

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

Designing for Dynamic Content

Script Handbook for Interactive Scientific Website Building

An Introduction to Developing ez Publish Extensions

Website Login Integration

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

HTML Tables. IT 3203 Introduction to Web Development

Sample Code with Output

FORM-ORIENTED DATA ENTRY

Online Multimedia Winter semester 2015/16

PHP Authentication Schemes

SQL Injection. Blossom Hands-on exercises for computer forensics and security

Internet Technologies

Online signature API. Terms used in this document. The API in brief. Version 0.20,

A basic create statement for a simple student table would look like the following.

Role Based Access Control. Using PHP Sessions

PHP Tutorial From beginner to master

2- Forms and JavaScript Course: Developing web- based applica<ons

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Direct Post Method (DPM) Developer Guide

Designing and Implementing an Online Bookstore Website

The PHP 5.4 Features You Will Actually Use

JavaScript and Dreamweaver Examples

HOTEL RESERVATION SYSTEM. Database Management System Project

GTPayment Merchant Integration Manual

PEAR. PHP Extension and Application Repository. Mocsnik Norbert Harmadik Magyarországi PHP Konferencia március 12., Budapest

Sample HP OO Web Application

MERCHANT INTEGRATION GUIDE. Version 2.8

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

Java Server Pages and Java Beans

Working with forms in PHP

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

Using Form Tools (admin)

Advanced Web Technology 10) XSS, CSRF and SQL Injection 2

SEEM4540 Open Systems for E-Commerce Lecture 06 Online Payment

Membuat Aplikasi Berita Sederhana

Web Programming with PHP 5. The right tool for the right job.

DeltaPAY v2 Merchant Integration Specifications (HTML - v1.9)

<option> eggs </option> <option> cheese </option> </select> </p> </form>

Cover Page. Dynamic Server Pages Guide 10g Release 3 ( ) March 2007

Chapter 22 How to send and access other web sites

Cifratura Dati in Tabelle MySQL

SQL Injection for newbie

Part II of The Pattern to Good ILE. with RPG IV. Scott Klement

Introduction to Server-Side Programming. Charles Liu

Web Development 1 A4 Project Description Web Architecture

İNTERNET TABANLI PROGRAMLAMA- 13.ders GRIDVIEW, DETAILSVIEW, ACCESSDATASOURCE NESNELERİ İLE BİLGİ GÖRÜNTÜLEME

CodeIgniter for Rapid PHP Application Development

Server-side scripting with PHP4

HTML Forms and CONTROLS

A Brief Introduction to MySQL

Application note: Connecting the to a Database

Website Planning Checklist

APEX_ITEM and Dynamic Tabular Forms

Understanding Cross Site Scripting

Webapps Vulnerability Report

Implementing Specialized Data Capture Applications with InVision Development Tools (Part 2)

2. Modify default.aspx and about.aspx. Add some information about the web site.

Online shopping store

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

Li Yicheng. Development of a blog system using CodeIgniter framework

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

Fortigate SSL VPN 4 With PINsafe Installation Notes

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

Paging, sorting, and searching using EF Code first and MVC 3. Introduction. Installing AdventureWorksLT database. Creating the MVC 3 web application

2. Follow the installation directions and install the server on ccc

Intro to Databases. ACM Webmonkeys 2011

Redundant Storage Cluster

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";! SET time_zone = "+00:00";!

Example for Using the PrestaShop Web Service : CRUD

Accessing External Databases from Mobile Applications

Brazil + JDBC Juin 2001, douin@cnam.fr

CSCI110 Exercise 4: Database - MySQL

14 Triggers / Embedded SQL

Further web design: HTML forms

Database Administration with MySQL

Contents. 2 Alfresco API Version 1.0

PROJECT REPORT OF BUILDING COURSE MANAGEMENT SYSTEM BY DJANGO FRAMEWORK

Now that we have discussed some PHP background

DIPLOMA IN WEBDEVELOPMENT

Web Development using PHP (WD_PHP) Duration 1.5 months

Real SQL Programming 1

Chapter 2: Interactive Web Applications

Linklok URL TM V2.90

Transcription:

CRUD USING PHP (Create, Read, Update and Delete on Database) Create Database and Table using following Sql Syntax. create database test; CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) NOT NULL, `age` int(3) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`id`) ); Index.php //fetching data in descending order (lastest entry first) $result=mysql_query("select * FROM users ORDER BY id DESC"); <title>homepage</title> <a href="add.html">add New Data</a><br/><br/> echo "<table width='80%' border=0>"; echo "<tr bgcolor='#cccccc'>"; echo "Name</td>"; echo "Age</td>"; echo "Email</td>"; echo "Update</td>"; echo ""; while($res=mysql_fetch_array($result)) echo ""; echo "".$res['name']."</td>"; echo "".$res['age']."</td>"; echo "".$res['email']."</td>"; echo "<a href=\"edit.php?id=$res[id]\">edit</a> <a href=\"delete.php?id=$res[id]\">delete</a></td>"; echo "</table>";

Config.php $conn = mysql_connect("localhost","root","") or die("cannot connected"); mysql_select_db("test",$conn); Add.HTML <head> <title>add Data</title> </head> <a href="index.php">home</a> <br/><br/> <form action="add.php" method="post" name="form1"> <table width="25%" border="0"> Name</td> <input type="text" name="name"></td> Age</td> <input type="text" name="age"></td> Email</td> <input type="text" name="email"></td> </td> <input type="submit" name="submit" value="add"></td> </table> </form> Add.php <head> <title>add Data</title> </head>

if(isset($_post['submit'])) $name=$_post['name']; $age=$_post['age']; $email=$_post['email']; // checking empty fields if(empty($name) empty($age) empty($email)) //if name field is empty if(empty($name)) echo "<font color='red'>name field is empty.</font><br/>"; //if age field is empty if(empty($age)) echo "<font color='red'>age field is empty.</font><br/>"; //if email field is empty if(empty($email)) echo "<font color='red'>email field is empty.</font><br/>"; //link to the previous page echo "<br/><a href='javascript:self.history.back();'>go Back</a>"; else // if all the fields are filled (not empty) //insert data to database $result=mysql_query("insert INTO users(name,age,email) VALUES('$name','$age','$email')"); //display success message echo "<font color='green'>data added successfully."; echo "<br/><a href='index.php'>view Result</a>"; Delete.php include("config.php"); //getting id of the data from url $id = $_GET['id']; //deleting the row from table $result=mysql_query("delete FROM users where id=$id");

//redirecting to the display page (index.php in our case) header("location:index.php"); Edit.php if(isset($_post['update'])) //here the id that we post is the same id that we get from url //id indicates the id of this data which we are editing //id is unique and a particular id is associated with particular data $id = $_POST['id']; $name=$_post['name']; $age=$_post['age']; $email=$_post['email']; // checking empty fields if(empty($name) empty($age) empty($email)) //if name field is empty if(empty($name)) echo "<font color='red'>name field is empty.</font><br/>"; //if age field is empty if(empty($age)) echo "<font color='red'>age field is empty.</font><br/>"; //if email field is empty if(empty($email)) echo "<font color='red'>email field is empty.</font><br/>"; else //updating the table $result=mysql_query("update users SET name='$name',age='$age',email='$email' WHERE id=$id"); //redirectig to the display page. In our case, it is index.php header("location: index.php"); //for displaying data of this particular data //getting id from url

$id = $_GET['id']; //selecting data associated with this particular id $result=mysql_query("select * from users where id=$id"); while($res=mysql_fetch_array($result)) $name = $res['name']; $age = $res['age']; $email = $res['email']; <title>edit Data</title> <a href="index.php">home</a> <br/><br/> <form name="form1" method="post" action="edit.php"> <table border="0"> Name</td> <input type="text" name="name" value= echo $name;> </td> Age</td> <input type="text" name="age" value= echo $age;> </td> Email</td> <input type="text" name="email" value= echo $email;> </td> <input type="hidden" name="id" value= echo $_GET['id'];> </td> <input type="submit" name="update" value="update"></td> </table> </form>