I'm trying to update text I've selected and displayed in a TextArea to my database. The text is selected and displayed so nothing wrong with the connection.php. But when I change the text and press save it does not update the text in the database, however it shows that the data is stored in the variables $tekstArea and $tekstIDArea. Could anyone help me out?
Here is my code:
<?php
session_start();
include "connection.php";
?>
<?php
//Get Resulsts from database
$query = "SELECT * FROM tekst";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result)) {
$tekstID = $row['tekstID'];
$text = $row['text'];
echo "<form method='POST' action=''>
<input name='tekstIDArea' value=" . $tekstID . ">
<br />
<textarea name='textArea' rows='20'>" . $text . "</textarea>
<br />
<button type='submit' name='submit' class='btn'>Save</button><br /><br />";
}
if (isset($_POST['submit'])) {
$tekstArea = $_POST['textArea'];
$tekstIDArea = $_POST['tekstIDArea'];
$sql = "UPDATE tekst SET 'text' = '$tekstArea'";
$res = mysqli_query($conn, $sql);
if(!$res)
{
echo "Could not update" . mysql_error() . "<br />";
echo $tekstArea . "<br />";
echo $tekstIDArea . "<br />";
}
mysqli_close($conn);
}
?>
Thanks in advance,
Ahnkheg
EDIT: Added form closing tag. Changed mysql_error() to mysqli_error($conn).