so i have this website that has all the info stored normally in the db in romanian language. also the site has an option for english and all the data is stored in the db in a weird way (haven't seen this till now)
so this is an entry in the translations table. 57 is the primary key, en is the language, 1 is the id of the translated story, title is the field in the stories table and "photographers of alba iulia" is the translated title
i have to add translations for title, description, and story main text (and later for each picture and so on)
i came up with this code:
$lang = "en";
$story_title = "title";
$stories = "stories";
$story_description = "abstract";
$story_text = "story_text";
if(isset($_POST['title']) && isset($_POST['description']) && isset($_POST['story_text'])) {
if(!empty($_POST['title'])){
$sql = "INSERT INTO translations (lang, tabel, cheie, camp, traducere) VALUES (:lang, :table, :story_id, :camp, :title)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':lang', $lang);
$stmt->bindParam(':table', $stories);
$stmt->bindParam(':story_id', $_GET['id']);
$stmt->bindParam(':camp', $story_title);
$stmt->bindParam(':title', $_POST['title']);
if($stmt->execute()){
$message = "titlul A FOST ADAUGAT";
if(!empty($_POST['description'])){
$sql = "INSERT INTO translations (lang, tabel, cheie, camp, traducere) VALUES (:lang, :table, :story_id, :camp, :description)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':lang', $lang);
$stmt->bindParam(':table', $stories);
$stmt->bindParam(':story_id', $_GET['id']);
$stmt->bindParam(':camp', $story_description);
$stmt->bindParam(':description', $_POST['description']);
if($stmt->execute()){
$message2 = "descrierea a fost adaugata";
if(!empty($_POST['story_text'])){
$sql = "INSERT INTO translations (lang, tabel, cheie, camp, traducere) VALUES (:lang, :table, :story_id, :camp, :text)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':lang', $lang);
$stmt->bindParam(':table', $stories);
$stmt->bindParam(':story_id', $_GET['id']);
$stmt->bindParam(':camp', $story_text);
$stmt->bindParam(':text', $_POST['text']);
if($stmt->execute()){
$message3 = "toate campurile au fost adaugate in baza de date";
// header("Location: http://localhost/auth2/index.php");
}
else {
$message2 = "EROARE in adaugarea textului povestii";
}
}
}
else {
$message2 = "EROARE in adaugarea descrierii";
}
}
}
else {
$message3 = "EROARE in adaugarea titlului";
}
}
}
else {
echo "nu ie setate boss";
}
and this is the form
<form action="translate.php" method="POST" name="myForm">
<input type="text" name="title" id="titlu_trad" placeholder="title" required>
<textarea name="description" id="desc_trad" placeholder="description" id="desc" required></textarea>
<textarea name="text" id="editor1" placeholder="story text" rows="10" cols="60" required></textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
<br>
<br>
<button type="submit" name="submit">Trimite formularul</button>
</form>
after i submit i get this error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cheie' cannot be null' in C:\xampp\htdocs\auth2\translate.php:75 Stack trace: #0 C:\xampp\htdocs\auth2\translate.php(75): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\auth2\translate.php on line 75
any advice?