mysql - Deleting a data in Database using php -
i need delete data on database using php code, have written code there error message. here php code(del.php):-
<!doctype html> <html> <body> <?php $conn = mysql_connect('localhost', 'root',''); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "delete register name='' "; if ($conn->query($sql) === true) { echo "record deleted successfully"; } else { echo "error deleting record: " . $conn->error; } $conn->close(); ?> </body> </html>
the database name 'selva' , table name 'register', in database file names "name,email,contact,address", need delete name or email or contact . how delete!!
//this delete whole row:
<!doctype html> <html> <body> <?php $servername = "localhost"; $username = "root"; $password = "your_password"; // add pw here $dbname = "selva"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } //this delete whole row $sql = "delete register 1 "; if ($conn->query($sql) === true) { echo "record deleted successfully"; } else { echo "error deleting record: " . $conn->error; } $conn->close(); ?> </body> </html>
//this delete columns set here:
<!doctype html> <html> <body> <?php $servername = "localhost"; $username = "root"; $password = "your_password"; // add pw here $dbname = "selva"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "alter table register drop name, drop email; drop contact; "; if ($conn->query($sql) === true) { echo "record deleted successfully"; } else { echo "error deleting record: " . $conn->error; } $conn->close(); ?> </body> </html>
hope :)
Comments
Post a Comment