2014-01-06 21 views
0

我正在嘗試構建論壇。我有一個包含一行標題,一行編輯鏈接和一行刪除鏈接的表。當我點擊編輯鏈接時,我被帶到edit.php,在那裏我有另一種形式插入新的主題標題。當我點擊「保存新主題」按鈕時,該行應該更新,但這是我的問題,標題保持不變。我一直在尋找這個網站(和一般的網絡)尋找解決方案,但沒有人似乎爲我工作。在php中編輯行

在forum.php我有這樣的代碼:

<?php   

     while ($row = mysqli_fetch_assoc($result)) 
     {        
      $subject = $row['subject'];      
      $id = $row['id'];   

    ?> 

      <tr> 
       <th><a href="viewtopic.php?id=<?php echo $row ['id']?> "> <?php echo $row ['subject']?> </a></th>       
       <th><a href="edit.php?id=<?php echo $row['id']?> ">Edit</a></th>      
       <th><a href="delete.php?id=<?php echo $row['id']?> ">Delete</a></th>  
      </tr> 
    <?php 
     } 
    ?> 

在edit.php我有這樣的代碼:

<div id="form"> 
     <form id='edit' action='edit.php' method='post' > 
      <fieldset> 
       <legend>Edit Topic</legend> 
        <br /> 
        <label for='name' >New Subject</label><br/> 
        <input type="text" id="subject" name="newsubject" /><br /> 

        <br/> 

        <input type='hidden' name='id' value='<?php echo $id ?>'/> 
        <input type="submit" name="save" value="Save New Topic" />    
      </fieldset> 
     </form> 
    </div> 

    <?php 
     if (isset($_POST['save'])) 
      { 
       $subject_save = $_POST['newsubject']; 


       require_once("db_connection.php"); 
       $conn = connectToMySQL(); 

       $id =$_POST['id']; 

       $query = "UPDATE tbl_topic SET subject = '$subject_save' WHERE id = 'id'"; 

       $result = mysqli_query($conn, $query) 
       or die("Error in query: ".mysqli_error($conn)); 

       header("Location: forum.php"); 
       die(); 
      } 
     ?>  
+0

「我點擊‘保存新主題’按鈕,該行應該被更新」 - 這行應在forum.php或edit.php更新? –

回答

0

編寫查詢作爲

$query = "UPDATE tbl_topic SET subject = '$subject_save' WHERE id = $id"; 
0

如果這不是打字時出錯

chan GE $query = "UPDATE tbl_topic SET subject = '$subject_save' WHERE id = 'id'";

$query = "UPDATE tbl_topic SET subject = '$subject_save' WHERE id = $id";

0
<div id="form"> 
     <form id='edit' action='edit.php' method='post' > 
      <fieldset> 
       <legend>Edit Topic</legend> 
        <br /> 
        <label for='name' >New Subject</label><br/> 
        <input type="text" id="subject" name="newsubject" value=<?php isse($_POST['newsubject']) ? "{$_POST['newsubject']}" : ""?> /><br /> 

<br/> 

<input type='hidden' name='id' value='<?php echo $id ?>'/> 
<input type="submit" name="save" value="Save New Topic" /> 
</fieldset> 
</form> 
</div> 

<?php 
if (isset($_POST['save'])) 
{ 
    $subject_save = $_POST['newsubject']; 


    require_once("db_connection.php"); 
    $conn = connectToMySQL(); 

    $id =$_POST['id']; 

    $query = "UPDATE tbl_topic SET subject = '$subject_save' WHERE id = $id"; 

    $result = mysqli_query($conn, $query) 
    or die("Error in query: ".mysqli_error($conn)); 

    header("Location: forum.php"); 
    die(); 
}