here is all my code
add.php
<?php
include_once('config.php');
if(isset($_POST['submit']))
{
$emri = $_POST['emri'];
$mbiemri = $_POST['mbiemri'];
$email = $_POST['email'];
$sql = "INSERT INTO users(emri,mbiemri,email) VALUES (:emri,:mbiemri,:email)";
$arti = $con->prepare($sql);
$arti->bindParam(':emri', $emri);
$arti->bindParam(':mbiemri', $mbiemri);
$arti->bindParam(':email', $email);
$arti->execute();
header("Location: index.php");
}
?>
<a href="index.php">Home</a>
config.php
<?php
$host = 'localhost';
$db = 'maj6a';
$user = 'root';
$pass = '';
try
{
$con = new PDO("mysql:host=$host; dbname=$db", $user, $pass);
} catch (Exception $e) {
echo "Diqka shkoi gabim!";
}
?>
<?php
include_once('config.php');
$sql = "SELECT * from users";
$prep = $con->prepare($sql);
$prep->execute();
$datas = $prep->fetchAll();
// var_dump($data);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
table
{
border: 1px solid black;
border-collapse: collapse;
}
th,td
{
border: 1px solid black;
padding: 5px 10px;
}
</style>
</head>
<body>
<table>
<thead>
<th>ID</th>
<th>Emri</th>
<th>Mbiemri</th>
<th>Email</th>
</thead>
<tbody>
<?php
foreach ($datas as $data) {
?>
<tr>
<td><?= $data['id'] ?></td>
<td><?= $data['emri'] ?></td>
<td><?= $data['mbiemri'] ?></td>
<td><?= $data['email'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<a href="index.php">Home</a>
</body>
</html>
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="add.php" method="POST">
<input type="text" name="emri" placeholder="Emri"><br>
<input type="text" name="mbiemri" placeholder="Mbiemri"><br>
<input type="email" name="email" placeholder="Email"><br>
<br><br>
<button type="submit" name="submit">Shto</button>
</form>
<a href="dashboard.php">Dashboard</a>
</body>
</html>
It's really irritating. I can't think of a reason the code might be wrong unless it's something very trivial, like a "" or a '' that's wrong. It's supposed to add data to SQL, then retrieve them from the other site. Ifa anyone could help me I would be very grateful.