Undefined Index When Declaring Variable
Why i'm getting undefined index when declaring variables? Currently using bootstrap.
<?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");
?> Create an Announcement / Reminder:
<div class="controls">
<textarea id="update" name="update"></textarea><br>
<button id="annbtn" class="btn btn-success">Update Announcement</button>
</div>
</div>
The update should only take place when you submit the form. Wrap your code inside this condition:
if ($_SERVER['REQUEST_METHOD'] == POST && isset($_POST['update']) {
$up = $_POST['update'];
mysql_query("UPDATE announcements SET content = $up");
}
链接地址: http://www.djcxy.com/p/21874.html
下一篇: 声明变量时未定义的索引