Im getting data from the mysql database and then ım writing them on the table with javascript but ı want to write only the data of the account that I'm logged in
this is my php file
<?php
require("sistem/baglan.php");
if($_POST){
$sahaid = $_POST["id"]
$list = $db-> query("SELECT *
FROM saat
INNER JOIN takim ON saat.takim_id = takim.id WHERE saat_durum='dolu' AND saha_id='$sahaid'")-
>fetchAll(PDO::FETCH_ASSOC);
echo json_encode($list);
}
?>
and this is my javascript file
import { girisKontrolSaha } from './saha-giris.js';
window.onload = function () {
girisKontrolSaha();
var oReq = new XMLHttpRequest();
oReq.onreadystatechange = function () {
if (oReq.readyState == XMLHttpRequest.DONE) {
var response = oReq.response;
response = JSON.parse(response);
console.log(response);
response.forEach(randevubilgi => {
console.log(randevubilgi)
var postNode = document.createElement('tr');
postNode.className = "randevutablosu"
var card =
'<td class="saathucre">'+
randevubilgi.saat +
'</td>'+
'<td class="takimadihucre">'+
randevubilgi.takimadi +
'</td>'+
'<td class="kontenjanhucre">'+
randevubilgi.takimkontejyan +
'</td>'+
'<td class="kurucuhucre">'+
randevubilgi.kurucu +
'</td>'+
'<td class="iptal">' + '<i class="las la-trash-alt" id="iptal-button" data-saatid="' +
randevubilgi.saat_id + '">'+'</i>'+ '</td>'
;
postNode.innerHTML = card;
var postList = document.getElementById("randevutablosu");
postList.appendChild(postNode);
});
}
}
oReq.open("GET", "../../backend/randevular.php");
oReq.send();
}
and also this is the function that writes the id and email of the account that im logged in to console
export function girisKontrolSaha() {
var user;
if (localStorage.getItem("auth-saha") != null) {
user = localStorage.getItem("auth-saha");
console.log("Giriş yapan kullanıcı : " + user);
console.log("Giriş yapan kullanıcı id : " + localStorage.getItem("auth-sahaid"));
var girislinkleri = document.getElementsByClassName("giris-linkleri");
for (var i = 0; i < girislinkleri.length; i++) {
girislinkleri[i].style.display = 'none';
}
var kullanicilinkleri = document.getElementsByClassName("kullanici-linkleri");
for (var i = 0; i < kullanicilinkleri.length; i++) {
kullanicilinkleri[i].style.display = 'display: block !important;';
}
} else {
var kullanicilinkleri = document.getElementsByClassName("kullanici-linkleri");
for (var i = 0; i < kullanicilinkleri.length; i++) {
kullanicilinkleri[i].style.cssText = 'display:none !important;';
}
window.location.replace("../../index.html");
}
}
ım getting the Uncaught SyntaxError when i run the code like this
but if i run my php file like this it works but it gets all the rows from the database
<?php
require("sistem/baglan.php");
$list = $db-> query("SELECT *
FROM saat
INNER JOIN takim ON saat.takim_id = takim.id WHERE saat_durum='dolu'")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($list);
?>
ım getting this error
Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.oReq.onreadystatechange (saha-randevular.js:11)
oReq.onreadystatechange @ saha-randevular.js:11
XMLHttpRequest.send (async)
window.onload @ saha-randevular.js:45
load (async)
(anonymous) @ saha-randevular.js:3
Use a session var to store the id of the user. That is the minimun you should do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.