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()); 
        }
    ?>

提前致谢

4

3 回答 3

0

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

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

<form action="editschool.php?schoolid=<?php echo $_GET['schoolid'];?>" ...
于 2012-11-19T12:53:08.657 回答
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>
于 2012-11-19T12:58:15.497 回答
0
$query = "UPDATE `tertiary_school` SET `tschool_name`='$tschool_name' WHERE `tschool_id`='$tschool_id'";
mysql_query($query) or die(mysql_error());
于 2012-11-19T12:59:11.627 回答