Jump to content

Database - INSERT fail no errors; SQL?


Ansego
Go to solution Solved by 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.