Я пытаюсь добавить текст из текстовой области на моем сайте в базу данных MySQL.
Ниже приведен код PHP, который добавляет текст в базу данных.
if (isset($_POST['text']))
{
$text = sanitizeString($_POST['text']);
$text = preg_replace('/\s\s+/', ' ', $text);
$query = "SELECT * FROM profiles WHERE user='$user'";
if (mysql_num_rows(queryMysql($query)))
{
queryMysql("UPDATE profiles SET text='$text' where user='$user'");
}
else
{
$query = "INSERT INTO profiles VALUES('$user', '$text')";
queryMysql($query);
}
}
else
{
$query = "SELECT * FROM profiles WHERE user='$user'";
$result = queryMysql($query);
if (mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
$text = stripslashes($row[1]);
}
else $text = "";
}
$text = stripslashes(preg_replace('/\s\s+/', ' ', $text));
И ниже код формы.
<textarea name='text' cols='40' rows='3'>$text</textarea><br />
Но когда данные вводятся, они отображаются в базе данных правильно, но не отображаются правильно. Смотрите изображения ниже:
Введенный текст
![the text that is entered the text that is entered](https://i.stack.imgur.com/sEbMh.png)
Как текст отображается на странице
![this is how the text is displayed this is how the text is displayed](https://i.stack.imgur.com/gLpHT.png)
Как текст в базе данных
![this is the text in the database this is the text in the database](https://i.stack.imgur.com/RLa7y.png)
Это код PHP, который отображает текст на странице.
$result = queryMysql("SELECT * FROM profiles WHERE user='$user'");
if (mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
echo stripslashes($row[1]) . "<br clear=left /><br />
Надеюсь, вы можете помочь !!
РЕДАКТИРОВАТЬ: добавлен дополнительный код PHP