I would like some help with my code. I've already searched answered questions on this site but haven't found anything that works unfortunately. I'm doing a website where you can write, save, delete and update notes. Now I'm trying to fix an update button were you can change a posted note using its unique ID. The update button is on a separate page from the notes, and you choose the ID of posted notes using using a drop-down menu showing the existing IDs in my database table. You choose it, write a new note and then click update.
This is my current code:
<li id="id_number"><label>ID number: <select name="id_number">
<option value =" ">Select number</option>
<?php $query = "SELECT * FROM notes";
$result2 = mysql_query($query);
while ($row = mysql_fetch_array($result2)) {
$id = $row ['id'];
$select = "";
if ($id == $idID2) {
$select = "selected" ;
}
?><option <?php print $select ?> value="<?php print $id; ?>"><?php print "$id";
?></option><?php
}
?>
</select>
</label></li>
<li id="note">New note:</li>
<li id="note"> <textarea rows="10" cols="30" name="note" value="<?php print $note;?>"/></textarea></li>
<li id="send"><input type="submit" name="submit" value="Update!"/></li>
</ul>
</form>
<?php
$id= $_POST ['id'];
$subject= $_POST ['subject'];
$note= $_POST ['note'];
?>
<?php
if (isset($_POST['submit'])) { //validates the data
$error="0";
if ( $note == "" ) {
$error++;
$wrong .= "<p> You forgot to write a new note.</p>";
}
if ($error > 0) {
print "<p><strong>You have made these errors:</strong></p>";
?>
<?php print $wrong; ?>
<?php
}
//if no errors
else {
$note = mysql_real_escape_string($note);
$note = htmlspecialchars($note);
$id = mysql_real_escape_string($id);
$id = htmlspecialchars($id);
$date = date("j/n, Y, H:i");
$query = ("UPDATE notes SET note='$note' WHERE id='$id'");
$result = mysql_query($query) or die (mysql_error());
if ($result) {
print "<p>Note updated!</p>";
}
}
}
?>
When choosing an existing ID and change the note and clicking update it says "Note updated" but the note in the database remains the same. What am i doing wrong?