声明变量时未定义的索引


Undefined Index When Declaring Variable

为什么我在声明变量时得到一个未定义的索引?当前使用引导程序。

<?php 
 mysql_connect("localhost", "root", "1234") or die(mysql_error());
 mysql_select_db("newitems") or die(mysql_error());
 $up =  $_POST['update']; 
 mysql_query("UPDATE announcements SET content = $up");

 ?>
 <div class="well well-small text-center">
 <h3>Create an Announcement / Reminder:<br>
 <form class="form-group" id="form-mahasiswa" method="POST" action="ad_post.php">
  <div class="control-group">
    <div class="controls">
        <textarea id="update" name="update"></textarea><br>
        
        <button id="annbtn" class="btn btn-success">Update Announcement</button>
    </div>
</div>

只有在您提交表单时,才会进行更新。将代码包装在此条件中:

if ($_SERVER['REQUEST_METHOD'] == POST && isset($_POST['update']) { 
   $up = $_POST['update']; 
   mysql_query("UPDATE announcements SET content = $up");
}