Jump to content

Heavy Code Problem... php guru needed maybe?


kelphyr

Recommended Posts

I've gotten an error from my script but I dont know why... how do i fix it?

 

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 '10,10,,,,,0xFFFFFFFF,7,2,,,,,,{},{},{}' at line 1

 

MY code:

$file = $_POST['filename'];
$handle = fopen($file, "r");

while (!feof($handle)) {
while($line = fgets($handle)){
	if(strpos($line,"//")===false){

	list($id,$aegisname,$name,$type,$price,$sell,$weight,$atk,$def,$range,$slot,$job,$upper,$gender,$loc,$wlv,$elv,$refineable,$view,$script,$equip,$unequip) = explode(",", $line);

	$query="REPLACE INTO `item_db` VALUES ($id,$aegisname,$name,$type,$price,$sell,$weight,$atk,$def,$range,$slot,$job,$upper,$gender,$loc,$wlv,$elv,$refineable,$view,$script,$equip,$unequip";
	mysql_query($query) or die(mysql_error());
	echo $name . " " . $type . "<br>";
	}
}
}

fclose($handle);

 

Starting of the file that we're reading

// Items Database
//
// Structure of Database:
// ID,AegisName,Name,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script }
//
// Healing Items
//=============================================================
0,DEFAULT,Default,0,,10,10,,,,,0xFFFFFFFF,7,2,,,,,,{},{},{}
501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}

Link to comment
https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/
Share on other sites

still not working got errors again

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 'VALUES ('0','DEFAULT','Default','0','','10','10','','','','','0

 

while (!feof($handle)) {
while($line = fgets($handle)){
	if(strpos($line,"//")===false){

	list($id,$aegisname,$name,$type,$price,$sell,$weight,$atk,$def,$range,$slot,$job,$upper,$gender,$loc,$wlv,$elv,$refineable,$view,$script,$equip,$unequip) = explode(",", $line);

	$query="REPLACE INTO `item_db` (VALUES ('$id','$aegisname','$name','$type','$price','$sell','$weight','$atk','$def','$range','$slot','$job','$upper','$gender','$loc','$wlv','$elv','$refineable','$view','$script','$equip','$unequip')";
	mysql_query($query) or die(mysql_error());
	//echo $name . " " . $type . "<br>";
	}
}
}

 

i know all values are in i tried to echo them and it works.

i really dont understand why i get all those errors lol

 

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 's_Feed','Monster Food','0','60','','150','','','','','0xFFFFFFF

 

$file = $_POST['filename'];
$handle = fopen($file, "r");

while (!feof($handle)) {
while($line = fgets($handle)){
	if(strpos($line,"//")===false){

	list($id,$aegisname,$name,$type,$price,$sell,$weight,$atk,$def,$range,$slot,$job,$upper,$gender,$loc,$wlv,$elv,$refineable,$view,$script,$equip,$unequip) = explode(",", $line);

	$query="REPLACE INTO `item_db` (`id`,`aegisname`,`name`,`type`,`price`,`sell`,`weight`,`atk`,`def`,`range`,`slot`,`job`,`upper`,`gender`,`loc`,`wlv`,`elv`,`refineable`,`view`,`script`,`equip_scr`,`unequip_scr`) VALUES ('$id','$aegisname','$name','$type','$price','$sell','$weight','$atk','$def','$range','$slot','$job','$upper','$gender','$loc','$wlv','$elv','$refineable','$view','$script','$equip','$unequip')";
	mysql_query($query) or die(mysql_error());
	//echo $name . " " . $type . "<br>";
	}
}
}

fclose($handle);

 

as for the database its at http://gamingtwilight.com/rodb/item_db.txt

Try out this tried and true technique:  echo $query, and take a look at the query.  Does something look odd?  Take a look at where the quotes are.

 

To fix it, use mysql_real_escape_string() on all of your strings.  You don't need to do it with the numeric values.  The best way to do this is to treat each item seperately on its own line.  Eg

 

$aegisname = mysql_real_escape_string($aegisname);
$name = mysql_real_escape_string($aegisname);

 

That will make sure that quotes inside the names do not conflict with the quotes required for mysql.

hmm it seems if u look at my database.. there are more "," then what i noted

 

501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}

 

{ itemheal rand(45,65),0; } .. at this one it should read between the { } and not see the "," in it... man this is uber hassling lol

 

$file = $_POST['filename'];
$handle = fopen($file, "r");

while (!feof($handle)) {
while($line = fgets($handle)){
	if(strpos($line,"//")===false){

	list($id,$aegisname,$name,$type,$price,$sell,$weight,$atk,$def,$range,$slot,$job,$upper,$gender,$loc,$wlv,$elv,$refineable,$view,$script,$equip,$unequip) = explode(",", $line);

	$aegisname = mysql_real_escape_string($aegisname);
	$name = mysql_real_escape_string($name);
	$script = mysql_real_escape_string($script);
	$equip = mysql_real_escape_string($equip);
	$unequip = mysql_real_escape_string($unequip);

	$query="REPLACE INTO `item_db` (`id`,`aegisname`,`name`,`type`,`price`,`sell`,`weight`,`atk`,`def`,`range`,`slot`,`job`,`upper`,`gender`,`loc`,`wlv`,`elv`,`refineable`,`view`,`script`,`equip_scr`,`unequip_scr`) VALUES ('$id','$aegisname','$name','$type','$price','$sell','$weight','$atk','$def','$range','$slot','$job','$upper','$gender','$loc','$wlv','$elv','$refineable','$view','$script','$equip','$unequip')";

	mysql_query($query) or die(mysql_error());
	//echo $name . " " . $type . "<br>";
	//echo $query;
	}
}
}

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.