--DELETE and INSERT queries in php which are commonly used ?
Answer
INSERT QUERY -----
<?php
include 'config.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';
}
}
Answer
INSERT QUERY -----
<?php
include 'config.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';
}
}
This comment has been removed by the author.
ReplyDeleteIncredible points. Sound arguments. Keep up the great work. Read on Full Stack Developer course in Chennai from our website.
ReplyDeleteThank you for sharing such great information. It has help me in finding out more great information.
ReplyDeleteWebsite development in UK