SQL
commands are instructions used to communicate with the database to perform
specific task that work with data.
Some
categories of commands used in SQL to perform various functions. SQL commands
can be used not only for searching the database, tables but also to perform
various other functions like, create the tables, add the data to tables, or
modify the data, drop the table and set permissions for users. Two query commands
of SQL are following there:
INSERT and DELETE queries in PHP which are commonly used ?
INSERT QUERY
<?php
if(isset($_POST['sub']))
{
$title =
mysql_escape_string($_POST['title']);
$sql="insert into
news (`title`) values('$title')";
$result=mysql_query($sql);
if($result)
{
echo"sucessfully
added";
}
else
{
echo"
error adding news";
}
}
DELETE QUERY
if(isset($_GET['delete'])){
// get row id to be
deleted and query delete
$id =
(int)$_GET['delete'];
if(mysql_query("delete
from `news` where `id`='$id'"))
{
echo
'News deleted successfully.';
}
else
{
echo
'Unable to delete row';
}
}
No comments:
Post a Comment