Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index.html
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="IndexStyle.css">
- <script src="functions.js"></script>
- <meta charset="utf-8">
- <meta name="description" content="An always learning AI">
- </head>
- <body>
- <img src="Resources/Images/roboAI.jpg" class="RoboAI" alt="RoboAI">
- <h1>The constantly learning AI</h1>
- <TextArea readonly name="Conversation" id="Conversation" class="Conversation" rows="18" cols="50">RoboAI: Welcome...</textarea>
- <textarea autofocus name="UserInput" id="UserInput" class="UserInput" placeholder="Communicate with the AI" rows="4" cols="50" onkeyup="CheckEnter(event, this)"></textarea>
- <button type="button" class="Refresh" onclick="Refresh()">Refresh</button>
- <button type="submit" name="Submit" id="Submit" class="Submit" onclick="Submit()")>Submit</button>
- </form>
- </body>
- </html>
- Functions.js
- function CheckEnter(e) {
- var k = (e.keyCode ? e.keyCode : e.which);
- if (k==13) {
- document.getElementById('Submit').click();
- }
- }
- function Refresh() {
- location.reload();
- }
- function Submit() {
- var xhttp;
- if (window.XMLHttpRequest) {
- // code for modern browsers
- xhttp = new XMLHttpRequest();
- } else {
- // code for IE6, IE5
- xhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- document.getElementById("Conversation").value = "";
- document.getElementById("Conversation").value = this.responseText;
- }
- };
- xhttp.open("GET", "AI.php?input=" + UserInput.value + "&convo=" + Conversation.value, true);
- xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhttp.send();
- UserInput.value = "";
- UserInput.focus;
- }
- AI.php
- <?php
- $Input = $_REQUEST['input'];
- $Convo = $_REQUEST['convo'];
- $Input = trim($Input);
- $Convo .= "\n\nUser: " . $Input;
- $exists = false;
- $dbhost = 'localhost';
- $dbuser = 'root';
- $conn = mysql_connect($dbhost,$dbuser);
- if(! $conn )
- die('Could not connect: ' . mysql_error());
- $sql = 'SELECT Input,Output FROM AI';
- mysql_select_db('aiinfo')or die (mysql_error());
- $retval = mysql_query( $sql, $conn );
- if(! $retval ) {
- die('Could not get data: ' . mysql_error());
- }
- while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
- if ($Input == $row['Input']) {
- $exists = true;
- $Output = $row['Output'];
- }
- }
- mysql_close($conn);
- if ($exists==true) {
- $Convo .= "\n\nRoboAI: " . $Output;
- } else {
- }
- echo $Convo;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement