0

I have created one link on different page (Delete). After that, I wrote following code to execute the query, but somehow it's showing the 'success' message, but it's not deleting particular record from database... Any suggestions?

<?php
        include_once('data_conn.php');
        $id=$_GET['id'];
             $sql = "DELETE FROM driver_info where id=$id";
                  echo $sql;
                    if(!$sql ) {
                                  echo '<script language="javascript">';
            echo 'alert("something went Wrong...:(((("); location.href="user-profile.php"';
            echo '</script>';
           }
                    else{
                       echstrong texto '<script language="javascript">';
            echo 'alert("successfully Deleted!!!"); location.href="user-profile.php"';
            echo '</script>';
            mysql_close();
                    }
?>
cdomination
  • 605
  • 1
  • 7
  • 25
Rkboss
  • 19
  • 6
  • 5
    You aren't executing your query – Jamie Bicknell Jul 01 '16 at 12:29
  • 1
    This code is open to SQL injections. – chris85 Jul 01 '16 at 12:32
  • 3
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 01 '16 at 12:47

2 Answers2

3

You are never executing the query you are just storing the query string in $sql. You should first execute the query with

mysqli_query($sql);

gowtham
  • 326
  • 1
  • 10
0

somehow it showing 'success' message but its not deleting

Because you are only echoing the query. Stop using mysql_*, instead do it with mysqli, and use mysqli_query.

http://php.net/manual/en/mysqli.query.php

Viktor Koncsek
  • 564
  • 3
  • 13