I
I
Ivan2016-08-22 08:43:19
PHP
Ivan, 2016-08-22 08:43:19

Why does not write the text to the database?

Actually, there is a small table with 4 fields (2 integer and 2 text fields, see Fig.)
Y9fiL3htOOs.jpg
Now I set both the table and the fields to compare the encoding: 'UTf8'
There is a Code that writes the data transferred from the form to the database in these fields, but for some reason if I pass 2 text fields (phraseseng and phrasesrus), then nothing is written there. If I suppose I write down the type field one, then everything is recorded well.
Here is the code:

header("Content-Type: text/html; charset=utf-8");
$type= (int)$_POST['Section'];
$phrases_eng = $_POST['phrases']; 
$phrases_rus = $_POST['translate'];
require_once 'database_connect.php';
$link = mysql_connect($host, $user, $password) or die("MySQL сервер недоступен!".mysql_error());
mysql_select_db($database,$link) or die("Could not select examples");
mysql_query("SET NAMES 'utf8'",$link);
$result=mysql_query("INSERT INTO `tourist_phrases` (`type`,`phrases_eng`,`phraserus`) VALUES ('$type','$phrases_eng','$phrases_rus')", $link);

I tried various methods that are written on the internet and something somehow does not help.
ps Data $phrases_eng and $phrases_rus are full.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-08-22
@trak_ivan

What am I doing wrong?

Your parenthesis is VALUES()not closed and $phrases_engwithout quotes.
Also, you are using the legacy mysql extension, not its modern equivalent: PDO or mysqli.
And yet, you insert data received from the client directly into the request. Welcome SQL Injection!
And yet, since you are cycling the layer of work with the database, it makes sense to transfer the actual connection to the database to a file database_connect.phpand connect it like this: $link = require_once 'database_connect.php';.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question