cześć wszystkim.
Proszę o podpowiedź co powinienem dodać do kodu żeby dane zapisywane do bazy danych miały polskie znaki, oraz co powinienem zrobić żeby polskie znaki mi się wyświetlały na stronie?
W bazie ustawiłem kodowanie utf8_polish_ci i gdy zmieniam litery na polskie znaki to strony nie moge odczytać, pojawiają mi się krzaczki, dodałem do pliku, poniższy kod, to nie za bardzo pomogło.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
kod
</body>
</html>
Gdy wyświetlam stronę w php to niestety kod powyżej kompletnie nie działa.
Poniżej kod odczytujący dane z bazy danych
read_template.php
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<?php
echo "<div class='right-button-margin'>";
echo "<a href='../standar.php' class='btn btn-primary pull-right'>";
echo "<span class='glyphicon glyphicon'></span> powrót";
echo "</a>";
echo "</div>";
if($total_rows>0){
echo "<div class='page-header'>
<h4>5 ostatnio dodanych instrukcji</h4>
</div>";
echo "<div>";
echo "<table class='table table-hover table-responsive table-bordered'>";
echo "<tr>";
echo "<th>Nazwa</th>";
echo "<th>Data</th>";
echo "<th>Funkcja</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<tr>";
echo "<td>{$name}</td>";
echo "<td>{$modified}</td>";
echo "<td>";
echo "<a href='read_one.php?id={$id}' class='btn btn-primary left-margin'>";
echo "<span class='glyphicon glyphicon-list'></span> Odczytaj";
echo "</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
// tell the user there are no users
else{
echo "<div class='alert alert-danger'>No instructions found.</div>";
}
echo "<div class='page-header'>
<h4>Filtr Instrukcji i regulaminów</h4>
</div>";
?>
<div>
<table class='table table-hover table-responsive table-bordered'>
<form method="post">
<tr>
<td>
<select id="category-select" name="cat_id_select" class="clear-right">
<option value="0" >Wyszukaj</option>
<option value="1">Programy szkolne</option>
</select>
</td>
<td>
<button type="submit" class="btn btn-primary">Wyszukaj Kategorii</button>
</td>
</tr>
</form>
<form method="post">
<tr>
<td>
<select id="subcategory-select" name="subcat_id_select" class="clear-right">
<option value="0">Wyszukaj</option>
<optgroup label="Programy szkolne">
<option value="1">profilaktyczny</option>
</select>
</td>
<td>
<button type="submit" class="btn btn-primary">Wyszukaj podkategorii</button>
</td>
</tr>
</form>
</table>
</div>
Tworzenie instrukcji
<?php
class Instruction{
private $conn;
private $table_name = "instructions";
public $id;
public $name;
public $description;
public $category_id;
public $subcategory_id;
public $image;
public $timestamp;
public function __construct($db){
$this->conn = $db;
}
// create user
function create(){
// insert query
$query = "INSERT INTO " . $this->table_name . "
SET name=:name,description=:description,
category_id=:category_id, subcategory_id=:subcategory_id, image=:image, created=:created";
$stmt = $this->conn->prepare($query);
// posted values
$this->name=htmlspecialchars(strip_tags($this->name));
$this->description=htmlspecialchars(strip_tags($this->description));
$this->category_id=htmlspecialchars(strip_tags($this->category_id));
$this->subcategory_id=htmlspecialchars(strip_tags($this->subcategory_id));
$this->image=htmlspecialchars(strip_tags($this->image));
// to get time-stamp for 'created' field
$this->timestamp = date('Y-m-d H:i:s');
// bind values
$stmt->bindParam(":name", $this->name);
$stmt->bindParam(":description", $this->description);
$stmt->bindParam(":category_id", $this->category_id);
$stmt->bindParam(":subcategory_id", $this->subcategory_id);
$stmt->bindParam(":created", $this->timestamp);
$stmt->bindParam(":image", $this->image);
if($stmt->execute()){
return true;
}else{
return false;
}
}
function readAll($from_record_num, $records_per_page){
$query = "SELECT
id, name, description, category_id, modified, created
FROM
" . $this->table_name . "
ORDER BY
created DESC
LIMIT
{$from_record_num}, {$records_per_page}";
$stmt = $this->conn->prepare( $query );
$stmt->execute();
return $stmt;
}
// used for paging users
public function countAll(){
$query = "SELECT id FROM " . $this->table_name . "";
$stmt = $this->conn->prepare( $query );
$stmt->execute();
$num = $stmt->rowCount();
return $num;
}
function readOne(){
$query = "SELECT name, description, category_id, subcategory_id, image, created, modified
FROM " . $this->table_name . "
WHERE id = ?
LIMIT 0,1";
$stmt = $this->conn->prepare( $query );
$stmt->bindParam(1, $this->id);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->name = $row['name'];
$this->description = $row['description'];
$this->category_id = $row['category_id'];
$this->subcategory_id = $row['subcategory_id'];
$this->created = $row['created'];
$this->modified = $row['modified'];
$this->image = $row['image'];
}
function update(){
$query = "UPDATE
" . $this->table_name . "
SET
name = :name,
description = :description,
category_id = :category_id,
subcategory_id = :subcategory_id,
modified = :modified
WHERE
id = :id";
$stmt = $this->conn->prepare($query);
$this->name=htmlspecialchars(strip_tags($this->name));
$this->description=htmlspecialchars(strip_tags($this->description));
$this->category_id=htmlspecialchars(strip_tags($this->category_id));
$this->subcategory_id=htmlspecialchars(strip_tags($this->subcategory_id));
$this->id=htmlspecialchars(strip_tags($this->id));
$this->timestamp = date('Y-m-d H:i:s');
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':description', $this->description);
$stmt->bindParam(":category_id", $this->category_id);
$stmt->bindParam(":subcategory_id", $this->subcategory_id);
$stmt->bindParam(":modified", $this->timestamp);
$stmt->bindParam(':id', $this->id);
if($stmt->execute()){
return true;
}
return false;
}
}
?>