Saturday 26 April 2014

Insert and Delete Query commonly used in php

         --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';
    }

}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Incredible points. Sound arguments. Keep up the great work. Read on Full Stack Developer course in Chennai from our website.

    ReplyDelete
  3. Thank you for sharing such great information. It has help me in finding out more great information.
    Website development in UK

    ReplyDelete