I am working on a PHP script to loop through a file to insert into the a database. Current the script is working but it is not inserting to the database. I have the connection working properly and I echo out the result just to ensure it is correct. It looks lines and loops accordingly (there is a lot more then 3 records but I did that for test purpose.
// Create connection
$conn = new mysqli($servername, $dbusername, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$myfile = fopen("words_alpha.txt", "r") or die("Unable to open file!");
//For Each line
$index = 1;
while($index <= 3){
$line = fgets($myfile);
$sql = "INSERT INTO WORD (wordID, `WORD`) VALUES (NULL,'$line');";
echo $sql;
$conn->query($sql); //We should be inserting here
echo "Success <br />\n";
sleep(1);
$index++;
}
Worth noting wordID is a PK and is incremented automatically hence the NULL value.