2014-04-19 68 views
0

這是我的上傳頁面,它也會顯示該頁面上傳的文件。 每次我按刪除,不會讓我到delete.php?id=7。它會像delete.php?id= <PHP我無法刪除上傳的文件

我可以知道最新的問題嗎?

<div id="content"> 
<form method="post" enctype="multipart/form-data"> 
<table width="350" border="0" cellpadding="1" 
cellspacing="1" class="box"> 
<tr> 
<td>Please select a file</td></tr> 
<tr> 
<td> 
<input type="hidden" name="MAX_FILE_SIZE" 
value="16000000"> 
<input name="userfile" type="file" id="userfile"> 
</td> 
<td width="80"><input name="upload" 
type="submit" class="box" id="upload" value=" Upload "></td> 
</tr> 
</table> 
</form> 
<table> 
<?php 
mysql_connect("localhost", "root", "") or die(mysql_error()) ; 
mysql_select_db("test") or die(mysql_error()) ; 

$sqlquery=mysql_query("SELECT * FROM upload"); 

while(list($id, $name) = mysql_fetch_array($sqlquery)){ 
echo "<tr>"; 
echo "<td>".$id."</td>"; 
echo "<td>".$name."</td>"; 
echo "<td><a href='delete.php?id='".$id."'> delete</a></td>"; 
echo "</tr>"; 
} 
?> 
</table> 
<?php 
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0) 
{ 
$fileName = $_FILES['userfile']['name']; 
$tmpName = $_FILES['userfile']['tmp_name']; 
$fileSize = $_FILES['userfile']['size']; 
$fileType = $_FILES['userfile']['type']; 
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile']))); 
$fp  = fopen($tmpName, 'r'); 
$content = fread($fp, filesize($tmpName)); 
$content = addslashes($content); 
fclose($fp); 
if(!get_magic_quotes_gpc()) 
{ 
    $fileName = addslashes($fileName); 
} 
$con = mysql_connect('localhost', 'root', '') or die(mysql_error()); 
$db = mysql_select_db('test', $con); 
if($db){ 
$query = "INSERT INTO upload (name, type, size, content) ". 
"VALUES ('$fileName', '$fileType', '$fileSize', '$content')"; 
mysql_query($query) or die('Error, query failed'); 
echo '<br/>File' .$fileName. ' uploaded'; 
mysql_close(); 
}else { echo "file upload failed"; 
    } 
} 
?> 
</div> 

,這裏是我的delete.php

<?php 

    mysql_connect("localhost","root","")or 
    die(mysql_error()); 
    mysql_select_db("test") or die(mysql_error()); 
    $sql="DELETE FROM upload WHERE id='$id'"; 
    $result=mysql_query($sql); 
      if(isset($_GET['id'])) { 
       $id=$_GET['id']; 
       echo 'deleted successfully.'; 
       echo "<BR>"; 
       mysql_query("DELETE FROM staff WHERE id = $id"); 
      header("Location: student_upload.php"); 
     }else { 
    echo "ERROR"; 
    } 
    ?> 
    <?php 
    mysql_close(); 
    ?> 
+0

雖然你的代碼_may WORK_,這是所有在彈出的錯誤做法彙編最近10年的網頁開發。我建議你找到關於更新標準[關注點分離,RESTful架構,模板,HTML 5 ...]的良好閱讀。 – moonwave99

回答

1

你的問題是與報價:

echo "<td><a href='delete.php?id='".$id."'> delete</a></td>"; 

如果id爲7,生成的HTML是:

<td><a href='delete.php?id='7'>delete</a></td> 

由於'在01之後結束,數字永遠不會傳遞給查詢字符串。這就好像你寫了<a href="foo.html" hello there people>click me</a>

爲了解決這個問題,請確保您的引號是正確的嵌套:

現在
echo '<td><a href="delete.php?id='.$id.'"> delete</a></td>'; 

你的鏈接是<td><a href="delete.php?id=7"> delete</a></td>

+0

謝謝so muchhhhhhhhhhhhhhhhhhhhhhhhhhhhh! – user3551743

+0

@ user3551743如果解決了您的問題,請接受答案。 – Djizeus