0

我在提交页面上有一个提交按钮,它返回空白且不更新,回显也是空白。

<?
    if (isset($_POST['submit'])) {
        $newtext = mysql_real_escape_string($_POST['text']);
        $doTextEdit = "UPDATE `$database_main`.`texts` SET `texts`.`text` = '$newtext' WHERE `texts`.`id` = '$sid' LIMIT 1" or die(mysql_error());

        $retval = mysql_query( $doArtistEdit, $main );
        if(! $retval )
        {
            die('Could not update data: ' . mysql_error());
        }
        header("Location: ".$_SERVER['HTTP_REFERER']);
        }
    ?>

这是表单代码

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="$ID" method="post">
        Song Name : <input type="text" name="title" value="<?php echo $row_song['title']; ?>"> by Artist Name :<input type="text" name="artist" value="<?php echo $row_artist['artist']; ?>"><br><?php echo $sid; ?><?php echo $database_main; ?><?php echo $doTextEdit; ?>
        Lyrics :<br><textarea name="text" cols="72" rows="20"><?php echo str_replace("\n","\n",$row_Recordset1['text']); ?></textarea><br>
        <input type="submit" name="editlyrics" value="Edit"></form>
4

2 回答 2

3

您正在检查是否$_POST['submit']已设置 -

if (isset($_POST['submit']))

但是您的提交按钮名称是editlyrics,所以它应该是 -

if (isset($_POST['editlyrics']))

在表单中添加隐藏输入 -

<input type="hidden" name="song_id" value="<?php echo $sid; ?>">

现在您的代码将类似于-

<?
if (isset($_POST['editlyrics'])) {
    $song_id = mysql_real_escape_string($_POST['song_id']);
    $newtext = mysql_real_escape_string($_POST['text']);
    $doTextEdit = "UPDATE `$database_main`.`texts` SET `texts`.`text` = '$newtext' WHERE `texts`.`id` = '$song_id' LIMIT 1" or die(mysql_error());

    $retval = mysql_query( $doTextEdit, $main );
    if(! $retval )
    {
        die('Could not update data: ' . mysql_error());
    }
    header("Location: ".$_SERVER['HTTP_REFERER']);
    }
?>

请注意,您不应该使用过时的mysql_函数编写代码,并学习mysqliPDO- php.net/manual/en/mysqlinfo.api.choosing.php

于 2012-10-22T23:49:18.507 回答
0

您正在设置 SQL 查询,$doTextEdit但您正在传递$doArtistEditmysql_query()函数。

于 2012-10-22T23:46:33.890 回答