size basit bir veri ekleme veri listeleme php kodu veriyorum bir kaç günden beri php yi elle yapay zekadan önceki gibi yazıyorum ve size basit veri ekleme listeleme veriyorum isteyenler kendilerine göre editleyerek kullana bilirler
database.php
ekle.php
post.php
posts.php
database.sql
kurulum ve çalışması ise şöyle
database.php ye sql bilgilerini yaz
database.sql i içe aktar
ekle.php den veri ekle
posts.php ye git ve tüm postları görüntüle
post.php?id=1 git ve tekil post görüntüle
database.php
PHP:
<?php
$connection = new mysqli(
"localhost",
"root",
"",
"test"
);
?>
ekle.php
PHP:
<?php
include ("database.php");
if ($_POST) {
$content=$_POST["content"];
$stmt = $connection->prepare("INSERT INTO post2 (content) VALUES (?)");
$stmt->bind_param("s", $content);
$stmt->execute();
$stmt->close();
}
?>
<form action="" method="POST">
<div>
<label for="content">İçerik Metni:</label><br>
<textarea id="content" name="content" rows="4" cols="50" required></textarea>
</div>
<br>
<button type="submit">Gönder</button>
</form>
post.php
PHP:
<?php
include("database.php");
$id = intval($_GET['id'] ?? 0);
$sql = "SELECT id, content, created FROM post2 WHERE id = $id";
$result = mysqli_query($connection, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
echo htmlspecialchars($row['id']) . "<br>";
echo htmlspecialchars($row['content']) . "<br>";
echo htmlspecialchars($row['created']) . "<br>";
}
}
?>
posts.php
PHP:
<?php
include ("database.php");
$sql = "SELECT id, content, created FROM post2";
$result = mysqli_query($connection, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
echo htmlspecialchars($row['id']) . "<br>";
echo htmlspecialchars($row['content']) . "<br>";
echo htmlspecialchars($row['created']) . "<br>";
}
}
?>
database.sql
SQL:
CREATE TABLE `post2` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`content` TEXT NOT NULL,
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
kurulum ve çalışması ise şöyle
database.php ye sql bilgilerini yaz
database.sql i içe aktar
ekle.php den veri ekle
posts.php ye git ve tüm postları görüntüle
post.php?id=1 git ve tekil post görüntüle



