i want to get all users with a specific name and this name is in a javascript variable and this code does not work how should i do it?
<table id="table">
<tr>
<td>id</td>
<td>name</td>
<td>info</td>
</tr>
</table>
<script>
var table = document.getElementById("table");
$.ajax({
type:"POST",
url:"process.php",
data:{name:"mike"}
});
</script>
<?php include 'process.php'; ?>
<?php foreach ($users as $user) : ?>
<script>
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML="<?= $user->id ?>";
cell2.innerHTML="<?= $user->name ?>";
cell3.innerHTML="<?= $user->info ?>";
</script>
<?php endforeach; ?>
php
$name = $_POST["name"];
$database = [
'host' => 'localhost',
'dbname' => 'dbname',
'user' => 'user',
'pass' => ''
];
try {
$db = new PDO("mysql:host={$database['host']};dbname={$database['dbname']}", $database['user'], $database['pass']);
} catch (PDOException $e) {
die("An error happend, Error: " . $e->getMessage());
}
function getAllUsers(){
global $db;
$sql = "SELECT * FROM users WHERE $name = name";
$stmt = $db->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
$users = getAllUsers();
the error is "Undefined array key "name" in process.php on line 2" could you help me to send my data to my php file and get a query based on that