0

当这个页面打开时,它会在下面的文本框中显示一条记录的内容:

在此处输入图像描述

在我编辑文本并单击将以前的注释替换为当前注释后:

在此处输入图像描述

使用以下代码将记录成功存储在数据库中ModifyNoteScript.php

$comment_update = mssql_query("UPDATE pmp_property__unit
    SET  
    comments = '$NOTE'
    WHERE 
    communityidy='$COMID' and
    unit='$UNIT'") 
             or die ("Changes to Record could not be Saved."); 

    if (!$comment_update)
    {
        $success=2;
    }
    else
    {
        $success=1;
    }


    header ('Location:ModifyNote.php?unit=' . $UNIT . '&COMID=' . $COMID . '&success=' . $success); 

header用户重定向回同一页面并显示此注释:

在此处输入图像描述

我遇到的问题是:

  1. 原来的注释在文本框中消失了,现在文本框是空白的,如上所示
  2. replace previous note with current 如果我再次单击,我会得到与上面相同的结果#1,此外,文本框中的任何内容都不会保存到数据库中。

这是带有文本框的页面的代码(编辑或删除注释):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../nav/occupancypop.css" rel="stylesheet" type="text/css"></link>
<script type='text/JavaScript' src='../scw.js'></script></head>
<script type="text/javascript">
<!--
function closewindow() {
parent.location = "occupancy2.php"
}

//-->
</script>

<body>
<div id="maincontentform">
<?php 

include '../Check.php';

  $success = $_GET['success'];
  if($success == 1)
  {
  echo '<span class="style4">*The note has been saved!</span><br />
    <br />'; 
  }
  elseif ($success==2)
  {
    echo '<span class="style4">*There was an error updating the note!</span><br />
    <br />';
  }



//GET the unit and community id
$UNIT = $_GET['unit'];
$COMID = $_GET['comid'];

include '../KiscoCustomConnect.php';

//Get the commnet
$Comment_Query = mssql_query("select top 1 comments from pmp_property__unit where communityidy='$COMID' and unit='$UNIT'");
if (mssql_num_rows($Comment_Query)>0)
{
$Comment=mssql_result($Comment_Query,0,'comments');
}
else
{
$Comment='';
}
?>

<span class="MainTitle">
 Edit or Delete the Note</span>
  <p><br />
  <table width="596" border="0" cellspacing="0" cellpadding="0" id="maintable">
    <tr class="odd">
      <td width="164"><div class="pickform">
        <ul>
          <li> 
            <div align="center">
              <p><strong><img src="../media/_space.gif" alt="" width="135" height="1" /><br />
                Update Notes</strong><br />
  <?php  echo 'for unit ' . $UNIT ?>
            </div>
          </li>
        </ul>
  </div></td>
      <td width="431">
        <form action="ModifyNoteScript.php" method="post"  />
        <input name="Comment" type="hidden" value="<?php echo $Comment; ?>" />
        <input name="UNIT" type="hidden" value="<?php echo $UNIT; ?>" />
        <input name="COMID" type="hidden" value="<?php echo $COMID; ?>" />
        <textarea name="Comment" cols="55" rows="6" class="text1" id="Comment"><?php echo $Comment; ?></textarea>
        <br />
        <input type="submit" name="sendnotify" class="formbutton" id="Submit" value="Replace previous note with current" />
      </form></td>
    </tr>


  </table>
  <blockquote>
    <p><br />

<?php      
  if($success == 3)
  {
 echo '<input type="button" name="Cancel3" class="formbutton2" id="Cancel3" value="Close" onclick="closewindow2();" />';
}
else
{
 echo '<input type="button" name="Cancel3" class="formbutton2" id="Cancel3" value="Close" onclick="closewindow();" />';
}
?>      <br />
      <br />
    </p>
  </blockquote>
</div>
</body>
</html>

我究竟做错了什么?我怀疑它与header?

4

3 回答 3

1

从我看到的情况来看,您在其他情况下设置

else
{
   $Comment='';
}

您进入 else 案例的原因如下:

您使用小写来访问$_GET['comid'],但是当您将其设置为大写&COMID=时。我尝试了以下方法:

$arr['a'] = 'a';
echo $arr['A']; //echoes blank (false)

你的情况:

$_GET['COMID'] = 'test';
var_dump($_GET['comid']); // results in undefined index comid

所以我会在尝试获取值时将 comid 更改为大写。

于 2013-03-05T23:08:28.677 回答
1

尝试在 $Comment='Test' 中添加一些文本,以便您知道 mssql_num_rows 何时返回 0 行

于 2013-03-05T23:11:46.500 回答
1
 $comment_update = mssql_query("UPDATE pmp_property__unit
    SET  
    comments = '$NOTE'
    WHERE 
    communityidy=$COMID and
    unit='$UNIT'") 
             or die ("Changes to Record could not be Saved."); 
于 2013-03-06T00:01:36.587 回答