0
votes

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>

1
You are using the variable $_POST['update']; which is not set until you post the form.Jens W
What do i need to do?Kim Octaviano

1 Answers

0
votes

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");
}