I have a batchcode.txt which contains list of batch code.
645863
302422
430307
821773
599738
671768
732159
and so on
I have a table in my database which is called batchcode with fields 'id','batchcode'.
My problem is it wont insert my text file into my table called batchcode. I already did the import and select table but nothing works...
I need some help can anyone help me please.
<?php
$host= "localhost";
$user= "root";
$pass= "";
$db="klayton";
$connect= mysql_connect($host,$user,$pass);
if (!$connect)die ("Cannot connect!");
mysql_select_db($db, $connect);
$file = fopen("batchcode.txt","r");
while(! feof($file))
{
$sql = "INSERT INTO batchcode( batchcode ) VALUES ('fgets($file)')"; //Insert every read line from txt to mysql database
mysql_query($sql);
}
fclose($file);
?>
I got an error that says "Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\test\index.php on line 22"
batchcode.txtin practice (megabytes or terabytes)? Do you have sysadmin access to the (Web & PHP) server?fgets()function will not be called the way it's currently written. You need to concatenate the value instead, i.e.$sql = "INSERT INTO batchcode( batchcode ) VALUES ('".fgets($file)."')";- Note that this is still vulnerable to SQL injection though. You should stop using the deprecatedmysql_*functions and switch to MySQLi / PDO (and start using prepared statements, so you're free from the risk of SQL injections).mysql_query()can only execute one query at most.INSERT INTO tableName (fieldname) VALUES ('value1'),('value2')...('valuen');