Jump to content

[SOLVED] MySql query problems


MrBillybob

Recommended Posts

Hello

 

      This code gets 1000 results out of a csv file and then puts it into a database. My Problem....it only inserts one row of data then it just stops inserting the data into the database.

 

 

<?php

$args['userid']  = 'blah';
$args['charid']  = 'blahblah';
$args['userkey'] = 'blahblahblahblahblahblahblahblahblahblahblahblahblahblahblah';


$auth  = "userid="       .$args['userid'];
$auth .= "&apikey="      .$args['userkey'];
$auth .= "&characterID=" .$args['charid'];


$head = "POST /corp/WalletJournal.csv.aspx HTTP/1.0\r\n";
$head .= "Host: api.eve-online.com\r\n";
$head .= "Content-Type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: " . strlen($auth) . "\r\n";
$head .= "Connection: close\r\n\r\n";

$fp = fsockopen ('api.eve-online.com', 80, $errno, $errstr, 30);

if (!$fp) {
	echo 'fsock failed; damn muppets! '.$errstr;
	exit();
}

fputs($fp, $head);
fputs($fp, $auth);

$header = 1;
$count = 0;
    while ($line = fgets ($fp))
    {
    
        if ($line == "\r\n")
        {
            $header = 0;
        }
        if ($header)
        {
            $http_header .= $line;
        }
        else
        {
            $count = $count + 1;
		list($date, $refID, $refType, $ownerName1, $ownerName2, $argName1, $amount, $balance, $reason) = explode(",", fgets ($fp));
		$data_in[$count]['date'] = $date;
		$data_in[$count]['refID'] = $refID;	
		$data_in[$count]['refType'] = $refType;
		$data_in[$count]['ownerName1'] = $ownerName1;
		$data_in[$count]['ownerName2'] = $ownerName2;
		$data_in[$count]['argName1'] = $argName1;
		$data_in[$count]['amount'] = $amount;
		$data_in[$count]['balance'] = $balance;
		$data_in[$count]['reason'] = $reason;
        }
    } 

fclose ($fp);

////////
//////// mysql conncet stuff
////////
////////

$server1 = mysql_connect($sname, $suname ,$supname);
$server1 = mysql_select_db($dbname, $server1);

for ($i = 3; $i <= $count; $i++) {

	$sql = 'INSERT INTO `eve_wallet` (`date`, `refID`, `refType`, `ownerName1`, `ownerName2`, `argName1`, `amount`, `balance`, `reason`) VALUES (\'' . $data_in[$i][date] . '\', \'' . $data_in[$i]['refID'] . '\', \'' . $data_in[$i]['refType'] . '\', \'' . $data_in[$i]['ownerName1'] . '\', \'' . $data_in[$i]['ownerName2'] . '\', \'' . $data_in[$i]['argName1'] . '\', \'' . $data_in[$i]['amount'] . '\', \'' . $data_in[$i]['balance'] . '\', \'' . $data_in[$i]['reason'] . '\');';
	$results = mysql_query($sql);
	if (!$results) {
		echo $i . " didnt work <br />";
	} else {
		echo $i . " worked <br />";
	}
	$sql = "";
}
mysql_close();
?>

 

If you can find anything wrong with my code please help me fix it. This is using the eve-online API.

Link to comment
https://forums.phpfreaks.com/topic/61953-solved-mysql-query-problems/
Share on other sites

I just got an error...

 

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Club', 'Rampage Eternal', 'EVE System', '400000000.00', '946537944.29', ' ')' at line 1"

 

What may cause this?

$sql = 'INSERT INTO `eve_wallet` (`date`, `refID`, `refType`, `ownerName1`, `ownerName2`, `argName1`, `amount`, `balance`, `reason`) VALUES (\'2007-07-24 19:21:00\', \'1137834593\', \'Office Rental Fee\', \'The Capitals' Club\', \'Rampage Eternal\', \'EVE System\', \'400000000.00\', \'946537944.29\', \'\');';

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.