【问题标题】:Undefined Index When Declaring Variable声明变量时未定义的索引
【发布时间】:2015-01-14 18:14:11
【问题描述】:

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

<?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>

【问题讨论】:

标签: php variables indexing undefined


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 2012-04-09
  • 1970-01-01
  • 2020-04-12
  • 2019-12-04
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-20
相关资源
最近更新 更多