从fancybox iframe表单中更新数据库

时间:2012-11-19 12:46:47

标签: php mysql fancybox

我正在尝试编写一个代码,您可以通过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()); 
        }
    ?>

提前致谢

3 个答案:

答案 0 :(得分:0)

表单发布数据时没有$ _GET ['schoolid'] ..

您可以将表单操作属性更新为

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

答案 1 :(得分: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>

答案 2 :(得分:0)

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