2015-10-27 113 views
0

時所顯示的錯誤,我有那些幫助更新和刪除表中的一行代碼:沒有更新和刪除

HTML:

<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
    <th>ID</th> 
    <th>Name</th> 
    <th>Informations</th> 
    <th>Actions</th> 
    <tr> 
     <td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
     <td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
     <td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
     <td> 
      <form action="update_del.php" method="post"> 
       <input class="imgClass_update" type="submit" name="submit1" value="" /> 
       <input class="imgClass_dell" type="submit" name="submit2" value=""/> 
      </form> 
     </td> 
    </tr> 
    <tr> 

PHP:

<?php 
require_once('../include/global.php'); 
$id=$_POST['id']; 
if(isset($_POST['submit1'])) 
{ 
    $name=$_POST['med_name']; 
    $info=$_POST['info']; 

    $sql = "UPDATE med SET med_name='$name', 
          info='$info' 
          WHERE id='$id'"; 
    $result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con)); 

    if($result){ 
     header("location:med.php"); 
    } 
    else 
    { 
     header("location:update_false.php"); 

    } 
} 
if(isset($_POST['submit2'])) 
{ 
    $sql = "DELETE FROM med WHERE id='$id'"; 
    $result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con)); 
    if(mysqli_affected_rows($con) == 1) 
    { 
     header("location:med.php"); 
    } 
    else 
    { 
     header("location:update_false.php"); 

    } 
} 
?> 

沒有什麼更新或刪除。並沒有顯示錯誤。如果有人可以幫助我,我認爲這個問題太簡單了,但是看不到它在哪裏。

+0

那麼你的概率將不會看到錯誤,因爲您重定向之前,你甚至可以看到一個錯誤.. +你不張貼任何東西因爲你的表單只包含提交按鈕,而不是你正在尋找的輸入字段...... – Naruto

+0

你能修復代碼嗎? – droidnation

回答

3

您正在將<form>標籤放置在錯誤的地方。

因此,你的其他元素:idmed_nameinfo沒有的form孩子。

而他們沒有得到張貼。

您應該在表格之前開始<form>並在表格之後結束。

更正代碼:

<form action="update_del.php" method="post"> 
<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
<tr> 
<th>ID</th> 
<th>Name</th> 
<th>Informations</th> 
<th>Actions</th> 
</tr> 
<tr> 
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
<td> 
<input class="imgClass_update" type="submit" name="submit1" value="Update" /> 
<input class="imgClass_dell" type="submit" name="submit2" value="Delete"/>   
</td> 
</tr> 
</table> 
</form> 
+0

你能解決這個問題嗎? – droidnation

+0

@droidnation,已更新的答案,請立即檢查。 – Pupil

+0

先生,我需要回顯td內的id並使用id號碼進行更新。如何通過在td中回顯id並獲取操作頁面中的值來實現該目的? – droidnation

2

只是這樣做 -

<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
<form action="update_del.php" method="post"> 
<th>ID</th> 
<th>Name</th> 
<th>Informations</th> 
<th>Actions</th> 
<tr> 
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
<td> 

<input class="imgClass_update" type="submit" name="submit1" value="" /> 
<input class="imgClass_dell" type="submit" name="submit2" value=""/> 

</td> 
</tr> 
</form> 
+0

表格內表格不工作我猜...只是交叉檢查。 –

+0

@NiranjanNRaju以及表格與表格無關....它只需要提交的值應該放在表格裏面...... –

+0

@ManojSalvi你能解釋一下嗎? – droidnation