Kod1 query php ye gönderiyor oda soruyu eşleştirip cevabı gösteriyor. benim amacım burada sesionı kullanıcı adı gibi gönderip query üzerinde eşleştirmek.
[COLOR=#515365][FONT=consolas]<html lang="en">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]<head>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <meta charset="UTF-8">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <meta name="viewport" content="width=device-width, initial-scale=1.0">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <meta http-equiv="X-UA-Compatible" content="ie=edge">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <title>Chatbot with PHP, MySQL and JS fetch</title>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <link rel="stylesheet" href="bot.css">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]</head>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]<body>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]<div id="bot">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div id="container">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div id="header">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] İK'ya SOR[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div id="body">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <!-- This section will be dynamically inserted from JavaScript -->[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="userSection">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="messages user-message">Merhaba[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="seperator"></div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="botSection">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="messages bot-reply"> Merhaba <?php echo $_SESSION['username']; ?>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div class="seperator"></div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div> [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <div id="inputArea">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <input type="text" name="messages" id="userInput" placeholder="Sorunuzu yazınız." required>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <input type="submit" id="send" value="Sor">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </div>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] <script type="text/javascript">[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] document.querySelector("#send").addEventListener("click", async () => {[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] let xhr = new XMLHttpRequest();[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] var userMessage = document.querySelector("#userInput").value[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] let userHtml = '<div class="userSection">'+'<div class="messages user-message">'+userMessage+'</div>'+[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] '<div class="seperator"></div>'+'</div>'[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] document.querySelector('#body').innerHTML+= userHtml;[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] xhr.open("POST", "query.php");[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] xhr.send(`messageValue=${userMessage}`);[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] xhr.onload = function () {[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] let botHtml = '<div class="botSection">'+'<div class="messages bot-reply">'+this.responseText+'</div>'+[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] '<div class="seperator"></div>'+'</div>'[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] document.querySelector('#body').innerHTML+= botHtml;[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] }[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] })[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </script>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] </body>[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]</html>[/FONT][/COLOR]Kod2 Query php burada da gelen soruyu kullanıcı ile eşleştirip karşılığındaki cevabı göndermesini istitorum[COLOR=#515365][FONT=consolas]if($conn)[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]{[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] $user_messages = mysqli_real_escape_string($conn, $_POST['messageValue']);[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] $query = "SELECT * FROM chatbot WHERE messages LIKE '%$user_messages%' , ";[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] $makeQuery = mysqli_query($conn, $query);[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] if(mysqli_num_rows($makeQuery) > 0)[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] {[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] $result = mysqli_fetch_assoc($makeQuery);[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] [/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] echo $result['response'];[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] }else{[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] echo "Üzgünüm sorunuzu anlamadım.";[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] }[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]}else {[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas] echo "Bağlantı hatası" . mysqli_connect_errno();[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]}[/FONT][/COLOR]
[COLOR=#515365][FONT=consolas]?>[/FONT][/COLOR]