Separació codis php
diff --git a/index.php b/index.php
index 03b289d..9f363ab 100644
--- a/index.php
+++ b/index.php
@@ -4,6 +4,8 @@
<title>Pàgina de benvinguda</title>
<link rel="stylesheet" href="./css/basic.css" />
<link rel="stylesheet" href="./css/login.css" />
+
+ <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<div id="outter-container">
@@ -11,46 +13,18 @@
<h1>Selecciona el teu nom</h1>
<h3>Per entrar al joc de la Pastanaga Assessina</h3>
<form action="main.php" method="GET">
- <select name="user">
- <?php
- // Define MySQL login variables
- $servername = "fdb22.awardspace.net";
- $username = "3155560_users";
- $password = "btechnoro@fox4news.info";
-
- // Create connection
- $conn = new mysqli($servername, $username, $password, "3155560_users");
- if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
- $conn->set_charset("utf8");
-
- // Do the query
- $query = "SELECT * FROM users";
-
- // Fetch the information of the user
- if ($result = $conn->query($query)) {
- while ($row = $result->fetch_row()) {
- $id = $row[0];
- $nomcomplet = $row[1];
- $curs = $row[2];
- $grau = $row[3];
- $quimata = $row[4];
-
- // Echo the options
- echo "<option value='".$id."'>".$nomcomplet."</option>\n";
- }
- $result->close();
- } else {
- die("Wrong query: " . $query);
- }
-
- // Close connection
- $conn->close();
- ?>
+ <select name="user" id="list">
</select>
<input type="submit" value="Entrar" />
</form>
</div>
</div>
+
+ <script>
+ $.post("./php/getusers.php", function(data, status){
+ $("#list").html(data);
+ });
+ </script>
</body>
</html>
diff --git a/js/utils.js b/js/utils.js
index b4f139a..92185d7 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -7,7 +7,7 @@
function send_request(id, msg) {
$.ajax({
- 'url': '../request.php',
+ 'url': '../php/request.php',
'type': 'GET',
'dataType': 'json',
'data': { 'id': id, 'msg': msg },
diff --git a/main.php b/main.php
index 960197b..31b4ae7 100644
--- a/main.php
+++ b/main.php
@@ -8,7 +8,7 @@
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="./js/utils.js"></script>
- <?php require 'login.php'; ?>
+ <?php require './php/login.php'; ?>
<script>
if (<?=$user->mort?>) {
// User is dead
diff --git a/php/getusers.php b/php/getusers.php
new file mode 100644
index 0000000..f3f79e9
--- /dev/null
+++ b/php/getusers.php
@@ -0,0 +1,34 @@
+<?php
+ // Define MySQL login variables
+ $servername = "fdb22.awardspace.net";
+ $username = "3155560_users";
+ $password = "btechnoro@fox4news.info";
+
+ // Create connection
+ $conn = new mysqli($servername, $username, $password, "3155560_users");
+ if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
+ $conn->set_charset("utf8");
+
+ // Do the query
+ $query = "SELECT * FROM users";
+
+ // Fetch the information of the user
+ if ($result = $conn->query($query)) {
+ while ($row = $result->fetch_row()) {
+ $id = $row[0];
+ $nomcomplet = $row[1];
+ $curs = $row[2];
+ $grau = $row[3];
+ $quimata = $row[4];
+
+ // Echo the options
+ echo "<option value='".$id."'>".$nomcomplet."</option>\n";
+ }
+ $result->close();
+ } else {
+ die("Wrong query: " . $query);
+ }
+
+ // Close connection
+ $conn->close();
+?>
diff --git a/login.php b/php/login.php
similarity index 100%
rename from login.php
rename to php/login.php
diff --git a/request.php b/php/request.php
similarity index 100%
rename from request.php
rename to php/request.php