How can data from a WYSIWYG editor in a PHP website be stored in a database and retrieved for future use?
To store data from a WYSIWYG editor in a PHP website into a database, you can use PHP to retrieve the input from the editor, sanitize it to prevent SQL injection, and then insert it into the database. To retrieve the data for future use, you can query the database and display the content in the WYSIWYG editor.
// Code to store data from WYSIWYG editor into database
$input_data = $_POST['wysiwyg_data']; // Assuming the data is sent via POST
$clean_data = mysqli_real_escape_string($connection, $input_data); // Sanitize the data
$query = "INSERT INTO your_table (content) VALUES ('$clean_data')";
mysqli_query($connection, $query);
// Code to retrieve data from database and display in WYSIWYG editor
$query = "SELECT content FROM your_table WHERE id = $id"; // Assuming you have an ID to retrieve specific content
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$retrieved_data = $row['content'];
echo '<textarea name="wysiwyg_data">' . $retrieved_data . '</textarea>';
Related Questions
- What are the best practices for handling large calculations on a PHP-based portal to prevent performance issues?
- How can the use of floatval() help resolve calculation errors related to decimal values in PHP?
- How does using /mein-formular/ in the action attribute of an HTML form affect security compared to using PHP_SELF?