Advertisement
Guest User

AIfiles

a guest
Mar 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. Index.html
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <link rel="stylesheet" type="text/css" href="IndexStyle.css">
  7. <script src="functions.js"></script>
  8. <meta charset="utf-8">
  9. <meta name="description" content="An always learning AI">
  10. </head>
  11. <body>
  12. <img src="Resources/Images/roboAI.jpg" class="RoboAI" alt="RoboAI">
  13. <h1>The constantly learning AI</h1>
  14. <TextArea readonly name="Conversation" id="Conversation" class="Conversation" rows="18" cols="50">RoboAI: Welcome...</textarea>
  15. <textarea autofocus name="UserInput" id="UserInput" class="UserInput" placeholder="Communicate with the AI" rows="4" cols="50" onkeyup="CheckEnter(event, this)"></textarea>
  16. <button type="button" class="Refresh" onclick="Refresh()">Refresh</button>
  17. <button type="submit" name="Submit" id="Submit" class="Submit" onclick="Submit()")>Submit</button>
  18. </form>
  19. </body>
  20. </html>
  21.  
  22. Functions.js
  23.  
  24. function CheckEnter(e) {
  25. var k = (e.keyCode ? e.keyCode : e.which);
  26. if (k==13) {
  27. document.getElementById('Submit').click();
  28. }
  29. }
  30.  
  31. function Refresh() {
  32. location.reload();
  33. }
  34.  
  35. function Submit() {
  36. var xhttp;
  37. if (window.XMLHttpRequest) {
  38. // code for modern browsers
  39. xhttp = new XMLHttpRequest();
  40. } else {
  41. // code for IE6, IE5
  42. xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  43. }
  44. xhttp.onreadystatechange = function() {
  45. if (this.readyState == 4 && this.status == 200) {
  46. document.getElementById("Conversation").value = "";
  47. document.getElementById("Conversation").value = this.responseText;
  48. }
  49. };
  50. xhttp.open("GET", "AI.php?input=" + UserInput.value + "&convo=" + Conversation.value, true);
  51. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  52. xhttp.send();
  53.  
  54. UserInput.value = "";
  55. UserInput.focus;
  56. }
  57.  
  58. AI.php
  59.  
  60. <?php
  61. $Input = $_REQUEST['input'];
  62. $Convo = $_REQUEST['convo'];
  63. $Input = trim($Input);
  64. $Convo .= "\n\nUser: " . $Input;
  65. $exists = false;
  66. $dbhost = 'localhost';
  67. $dbuser = 'root';
  68. $conn = mysql_connect($dbhost,$dbuser);
  69. if(! $conn )
  70. die('Could not connect: ' . mysql_error());
  71.  
  72. $sql = 'SELECT Input,Output FROM AI';
  73. mysql_select_db('aiinfo')or die (mysql_error());
  74. $retval = mysql_query( $sql, $conn );
  75. if(! $retval ) {
  76. die('Could not get data: ' . mysql_error());
  77. }
  78.  
  79. while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  80. if ($Input == $row['Input']) {
  81. $exists = true;
  82. $Output = $row['Output'];
  83. }
  84.  
  85. }
  86. mysql_close($conn);
  87. if ($exists==true) {
  88. $Convo .= "\n\nRoboAI: " . $Output;
  89. } else {
  90.  
  91. }
  92. echo $Convo;
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement