-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessbase.php
More file actions
47 lines (40 loc) · 1.39 KB
/
Copy pathguessbase.php
File metadata and controls
47 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once('connection.php');
// Create the words table if it doesn't exist
$sql = "CREATE TABLE IF NOT EXISTS words (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
word VARCHAR(255) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table words created successfully\n";
} else {
echo "Error creating table: " . mysqli_error($conn) . "\n";
}
// Read from the text file and insert words of length between 5 to 10
$filename = "words.txt";
$file = fopen($filename, "r");
if ($file) {
while (($word = fgets($file)) !== false) {
// Trim the word
$word = trim($word);
// Insert the word if it is between 5 to 10 characters long
if (strlen($word) >= 5 && strlen($word) <= 10) {
$sql = "SELECT * FROM words WHERE word = '$word'";
if (mysqli_query($conn, $sql)->num_rows == 0) {
$sql = "INSERT INTO words (word) VALUES ('$word')";
if (mysqli_query($conn, $sql)) {
echo "Word '$word' inserted successfully\n";
} else {
echo "Error inserting word '$word': " . mysqli_error($conn) . "\n";
}
} else {
echo "Word '$word' already exists\n";
}
}
}
fclose($file);
} else {
echo "Error reading file\n";
}
$conn->close();
?>