2012-11-19 183 views
1

我嘗試寫的代碼,你可以通過一個的fancybox iframe中更新數據庫

我的代碼犯規裏面的表單更新數據庫的內容似乎即使顯示沒有錯誤工作。數據庫沒有更新

這裏是我的代碼

editschool.php(這是我的fancybox iframe的內容)

<?php 
    $temp = mysql_query("SELECT * from tertiary_school where tschool_id = $_GET[tschool_id]"); 
    $temp = mysql_fetch_array($temp); 
    ?> 
    <center> 
    <form class="form-inline" method = 'post' enctype="multipart/form-data"> 
    <table> 
    <tr> 
    <td width="40%"> 
    Edit School Name: 
    </td> 
    <td> 
    <input name = "tschool_name" type="text" class="input-xlarge" id = "tschool_name" value="<?php echo $temp[tschool_name]; ?>"><button type="submit" value = "submit" name = "submit" class="btn btn-primary" onclick="event.preventDefault(); parent.$.fancybox.close();">Save Changes</button> 
    </td> 
    </tr> 
    </table> 
    </form> 
    </center> 
    <?php 
    if(isset($_POST['submit'])) 
     { 
      $tschool_name = $_POST['tschool_name']; 
      $tschool_id = $_GET['tschool_id']; 

      mysql_query("UPDATE tertiary_school SET tschool_name=$tschool_name WHERE tschool_id=$tschool_id") or die(mysql_error()); 
     } 
    ?> 

在此先感謝

+0

嘗試呼應'$ tschool_name'和'$ tschool_id' – Ravi

+0

我沒有和正確的數據就出來了。 現在我的問題是爲什麼它不更新我的數據庫? 我是否需要在我的代碼中添加某種父標籤? – itsover9000

+0

如果一切越來越細見下文 – Ravi

回答

0

沒有$ _GET [ 'schoolid']當表單發佈其數據時。

您可以更新表單動作屬性,以便沿着

<form action="editschool.php?schoolid=<?php echo $_GET['schoolid'];?>" ... 
+0

我獲取變量來自我的父頁面,所以我的變量存在 – itsover9000

+0

它存在於加載時,但不是當表單被髮送時 – Dale

+0

我認爲這就是發生什麼.odd ... – itsover9000

0

嘗試下面的代碼和後期輸出。

<?php 
    $temp = mysql_query("SELECT * from tertiary_school where tschool_id = $_GET[tschool_id]"); 
    $temp = mysql_fetch_array($temp); 
    ?> 
    <center> 
    <form class="form-inline" method = 'post' enctype="multipart/form-data"> 
    <table> 
    <tr> 
    <td width="40%"> 
    Edit School Name: 
    </td> 
    <td> 
<input type="hidden" name="tschool_id" value="<?php echo $_GET[tschool_id];?>" /> 
    <input name = "tschool_name" type="text" class="input-xlarge" id = "tschool_name" value="<?php echo $temp[tschool_name]; ?>"><button type="submit" value = "submit" name = "submit" class="btn btn-primary" onclick="event.preventDefault(); parent.$.fancybox.close();">Save Changes</button> 
    </td> 
    </tr> 
    </table> 
    </form> 
    </center> 
+0

我試過但數據庫仍然不更新 – itsover9000

0
$query = "UPDATE `tertiary_school` SET `tschool_name`='$tschool_name' WHERE `tschool_id`='$tschool_id'"; 
mysql_query($query) or die(mysql_error());