Jump to content

Database - INSERT fail no errors; SQL?


Ansego

Recommended Posts

Hello,

 

 

I can't see what I am doing wrong, not getting any errors and the data is not storing the database, can you see what I've missed? (SQL Statement correct?)

 

Objective: Pull data from *.CSV and dump it into MySQL Database;

$fin = fopen('db/pc.csv','r') or die('cant open file');

$mysqli = new mysqli('localhost', 'user', 'password', 'aupostcode');

	if (mysqli_connect_errno()) {
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	}
		
	$mysqli->select_db("dbleads");
	

	If (!$mysqli) {
		die ('Could not connect: ' . mysqli_error());
	}
		echo "Connection succeeded <br />\n";
	
	while (($data=fgetcsv($fin,1000,","))!==FALSE) {
	
		$sqlstring = "INSERT INTO `aupostcode`.`tbl_aupc`
					(`PCode`,
					`Locality`,
					`State`,
					`Comments`,
					`Deliveryoffice`,
					`Presortindicator`,
					`ParcelZone`,
					`BSPnumber`,
					`BSPname`,
					`Category`,
					`Lat`,
					`Long`)
					VALUES
					('" . $data[0] . "',
					'" . $data[1] . "',
					'" . $data[2] . "',
					'" . $data[3] . "',
					'" . $data[4] . "',
					'" . $data[5] . "',
					'" . $data[6] . "',
					'" . $data[7] . "',
					'" . $data[8] . "',
					'" . $data[9] . "',
					'" . $data[10] . "',
					'" . $data[11] . "');
					";
	
		$mysqli->query($sqlstring);
	}
		echo "Insert Complete </br>";
		fclose($fin);
		$mysqli->close();

Kind regards and advance thanks.

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/287168-database-insert-fail-no-errors-sql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.