2013-06-26 52 views
0

我在這裏遇到了我的代碼問題。 我不知道爲什麼。PHP-SQL:刪除行

<h2>Delete Admins</h2><br/> 
    <?php 
$con=mysqli_connect("localhost","root","","poll"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

$result = mysqli_query($con,"SELECT * FROM admin"); 

echo "<table> 
<tr> 
<th>ID</th> 
<th>Username</th> 
<th>Action</th> 
</tr>"; 
?> 

<form name="form1" method="POST" action="del-all.php?id=<?php echo $row['admin_id'] ?>" /> 
<?php 
while($row = mysqli_fetch_array($result)) 
    { 
    echo "<tr>"; 
    echo "<td>" . $row['admin_id'] . "</td>"; 
    echo "<td>" . $row['login'] . "</td>"; 
    echo "<td><button>DELETE</button></td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 

mysqli_close($con); 
?> 
</form> 


這德爾 - all.php,在這裏我把我的數據。 我不知道如果我的錯誤是在形式還是在<按鈕> 或在「回聲」,動作或者甚至方法

德爾 - all.php

<?php 
    require_once('auth.php'); 
?> 
<?php 
$id =$_REQUEST['id']; 
$con=mysqli_connect("localhost","root","","poll"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

mysqli_query($con,"DELETE FROM admin WHERE admin_id = '$id'"); 


mysqli_close($con); 
?> 

<html> 
<head> 
<title>Successfully Deleted!</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 

<link href="../style.css" rel="stylesheet" type="text/css" /> 
<link href='../fonts/fonts.css' rel='stylesheet' type='text/css'> 


<script type="text/JavaScript"> 
<!-- 
setTimeout("location.href = 'index.php';",1500); 
--> 
    </script> 
</head> 
<body> 
<fieldset> 
<h1 style="color:white;"> 
Data Deleted Successfully! 
</h1> 
</fieldset> 
</body> 
</html> 
+2

這將有助於,如果你解釋你想要發生什麼,以及發生了什麼。 – Jessica

+0

總是強烈建議不要在此處提供數據庫用戶名/密碼/數據庫信息。但它看起來像你沒有提交按鈕code_num說 – Dave

回答

4

按鈕的類型應該是提交以提交表格

<button type="submit" name="btn">DELETE</button>