I want to create form where I have text which I can edit and save to database for later use it in other file. I wrote following code, text is showing great from database , but updating text by submit button don't work.
It is strange but after submit, echo "Successfully saved!" normally displays, but not updating.
$connection = new mysqli("localhost", "db", "password", "db");
$query = "SELECT text FROM mailtext";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result))
{
$text = iconv('iso-8859-2', 'utf-8', $row['text']);
echo'
<center>
<form id="mailtext" method="post">
<textarea name="text" style="width: 500px; height: 300px;">'.$text.'</textarea>
<input type="submit" name="submit" value="Save">
</form>
</center>
';
if(isset($_POST['submit'])) {
$query2 = "UPDATE mailtext SET text='.$text.' WHERE id=1";
mysqli_query($connection, $query2);
echo 'Successfully saved!';
}
}
If you have any question or something like this, please ask :) Yes, I tried to searching answers in other questions, but nothing helped.
mailtextis selected and only updated one ?mailtext.$textcontained a single quote