user6538098 user6538098 - 5 months ago 12
SQL Question

how can i delete the records from database in php

I have created one link on different page (Delete). after that i wrote following code to execute query but somehow it showing 'success' message but its not deleting particular record from database...any suggestion??

<?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();
}
?>

Answer

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

Comments