main.php1384 chars38 lines
In the above code, we first establish a connection with the MySQL database using the mysqli_connect()
function.
Next, we open the CSV file using the fopen()
function and read the headers and the data using the fgetcsv()
function.
We then create an associative array using the headers and the data, and sanitize the user data using the mysqli_real_escape_string()
function to prevent SQL injection.
Finally, we insert the sanitized user data into the MySQL database using the mysqli_query()
function within a loop that goes through all the rows of the CSV file.
At the end, we close the CSV file and MySQL database connections and output a success message.
gistlibby LogSnag