'trivial' problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iano
Forum Newbie
Posts: 7
Joined: Fri Jan 09, 2004 6:24 am

'trivial' problem

Post by iano »

why wont the following line parse? I'm just trying to define a string :)

$sqlline = "INSERT INTO `iptoc` (`IP_FROM` , `IP_TO` , `country_code` , `country_code2` , `country_name` ) VALUES (";
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Theres no end parentheses :wink:

Code: Select all

$sqlline = "INSERT INTO `iptoc` (`IP_FROM` , `IP_TO` , `country_code` , `country_code2` , `country_name` ) VALUES (");
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

$sqlline = "INSERT INTO `iptoc` (`IP_FROM` , `IP_TO` , `country_code` , `country_code2` , `country_name` ) VALUES (";
Do you want to use it like that:

mysql_query($sqlline '$ip','$ip_to','$code');

????

8O 8O 8O 8O 8O
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

That line works fine for me. Must be a different line.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Re: 'trivial' problem

Post by scorphus »

What is rising the parse error, PHP or MySQL? What is the parse error message? Should not be PHP because there is no problem with PHP parsing this string. Maybe it is another line just as Bennettman said. Please post the error message.
iano
Forum Newbie
Posts: 7
Joined: Fri Jan 09, 2004 6:24 am

Post by iano »

here is the whole file. I'm trying to read one file line by line and output it into many other files each with the same quote inserted at the beginning. You were right, there isn't a problem with that line, I moved it out of the for loop and it works fine. The parse error is on the print line (line 11)

the error message is:
Parse error: parse error in changedata.php on line 11

this is the file:
<?
$fileread=fopen("/iptocountry/ip-to-country.csv","r+");

$sqlline= "INSERT INTO `iptoc` (`IP_FROM` , `IP_TO` , `country_code` , `country_code2` , `country_name` ) VALUES (";

for($filename=0;!feof($fileread);$filename++){
//open a new file to store the next 600 lines in
$filewrite=fopen("/iptocountry/".#filename.".txt", "a");

//insert the first line of mysql
print $sqlline;
fwrite($filewrite, $sqlline);

//read and insert the first line of data
$line=fgets($fileread);
fwrite($filewrite,"),(".$line);

//read and write the next 599
for($linenumber=2;$linenumber<601;$linenumber++){
$line=fgets($fileread);
fwrite($filewrite,"),(".$line);
}
//put the closing ) in for mysql use
fwrite(#filewrite,")");
fclose($filewrite);
}

fclose($fileread);

echo "done"

?>
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

The error is at line 8. Correction:

Code: Select all

$filewrite=fopen("/iptocountry/".$filename.".txt", "a"); // $filename instead of #filename
[edit="Scorphus"]
Also below on line 24:

Code: Select all

fwrite($filewrite,")"); // $ instead of #
[/edit]
iano
Forum Newbie
Posts: 7
Joined: Fri Jan 09, 2004 6:24 am

Post by iano »

thanks mate
you legend!
Post Reply