2016-11-08 72 views
-1

我需要通過使用PHP代碼刪除數據庫上的數據,我寫了代碼,但有一些錯誤消息。 這裏是PHP代碼(del.php): -使用php刪除數據庫中的數據

<!DOCTYPE html> 
<html> 
<body> 
<?php 

$conn = mysql_connect('localhost', 'root',''); 

if ($conn->connect_error) { 

die("Connection failed: " . $conn->connect_error); 
} 

$sql = "DELETE FROM register WHERE name='' "; 

if ($conn->query($sql) === TRUE) 
{ 
    echo "Record deleted successfully"; 
} else { 
    echo "Error deleting record: " . $conn->error; 
} 
$conn->close(); 
?> 
</body> 
</html> 

數據庫名稱是「熱帶雨林」和表名「註冊」,在數據庫文件名是「名稱,電子郵件,聯繫方式,地址「,我需要刪除名稱或電子郵件或聯繫。如何刪除!

+0

這裏已經問過這麼多的時間 – Blueblazer172

+0

「但是有一些錯誤信息。」 http://stackoverflow.com/help/how-to-ask – e4c5

+0

@SelvaKumar你的錯誤信息是什麼? – Blueblazer172

回答

1

//這將刪除整行:

<!DOCTYPE html> 
<html> 
<body> 
<?php 

$servername = "localhost"; 
$username = "root"; 
$password = "your_password"; // add your pw from the 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 will delete the whole row 
$sql = "DELETE FROM register WHERE 1 "; 

if ($conn->query($sql) === TRUE) 
{ 
    echo "Record deleted successfully"; 
} else { 
    echo "Error deleting record: " . $conn->error; 
} 
$conn->close(); 
?> 
</body> 
</html> 

//這將只刪除列您在此處設置:

<!DOCTYPE html> 
<html> 
<body> 
<?php 

$servername = "localhost"; 
$username = "root"; 
$password = "your_password"; // add your pw from the 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> 


希望它會幫助你:)