kelphyr Posted February 19, 2007 Share Posted February 19, 2007 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 More sharing options...
btherl Posted February 19, 2007 Share Posted February 19, 2007 That doesn't need a guru You need single quotes (') around your string data in your "replace into" statement. You also need to decide what to do when a field is empty. Do you send '', or 0? Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188347 Share on other sites More sharing options...
marcus Posted February 19, 2007 Share Posted February 19, 2007 Also, end the query You have $query = "blah blah (values"; You nee $query = "blah blah (values)"; Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188351 Share on other sites More sharing options...
kelphyr Posted February 19, 2007 Author Share Posted February 19, 2007 how do i tell it to do nothing... when a field is empty? just leave it empty.. or put 0 Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188357 Share on other sites More sharing options...
ataria Posted February 19, 2007 Share Posted February 19, 2007 how do i tell it to do nothing... when a field is empty? just leave it empty.. or put 0 Just leave it empty . Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188359 Share on other sites More sharing options...
marcus Posted February 19, 2007 Share Posted February 19, 2007 Check if it's set if(isset($varname)){ return true; }else { return false; } Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188360 Share on other sites More sharing options...
kelphyr Posted February 19, 2007 Author Share Posted February 19, 2007 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. Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188370 Share on other sites More sharing options...
marcus Posted February 19, 2007 Share Posted February 19, 2007 Try doing something like this: $query = "REPLACE INTO `table` (`field1`,`field2`,`etc`) VALUES('$field1data','$field2data','$etcdata')"; Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188373 Share on other sites More sharing options...
kelphyr Posted February 19, 2007 Author Share Posted February 19, 2007 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 Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188391 Share on other sites More sharing options...
btherl Posted February 19, 2007 Share Posted February 19, 2007 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. Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188396 Share on other sites More sharing options...
kelphyr Posted February 19, 2007 Author Share Posted February 19, 2007 ok that worked BUT that fucked some of the data that went into the database.. its missing some code cuz it seems to have stoped at all " ' ".. o.o Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188402 Share on other sites More sharing options...
kelphyr Posted February 19, 2007 Author Share Posted February 19, 2007 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; } } } Link to comment https://forums.phpfreaks.com/topic/39112-heavy-code-problem-php-guru-needed-maybe/#findComment-188406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.