BioRiot Posted May 10, 2009 Share Posted May 10, 2009 I've been using this function in many places in 15,000+ lines of code, and it has NEVER done this. I've tested line by line and changed these values and value names a ton of times...but I'm totally stumped on this one. (I know newtxtLine() is a crappy function and I should probably use an associative table instead, but I really just want to know whats causing this problem) Here are snippets of the code that is giving me problems: (below the code I explain the actual problem) function giveFight($fid, $givewhat, $value){ include '/home/chuck/configSGame.phps'; include '/home/chuck/opendb.phps'; $result2 = mysql_query("UPDATE fight SET $givewhat = '$value' WHERE fid = $fid"); } function newtxtLine($fid, $newtxt){ include '/home/chuck/configSGame.phps'; include '/home/chuck/opendb.phps'; giveFight($fid, txt10, getFight($fid, txt9)); giveFight($fid, txt9, getFight($fid, txt8)); giveFight($fid, txt8, getFight($fid, txt7)); giveFight($fid, txt7, getFight($fid, txt6)); giveFight($fid, txt6, getFight($fid, txt5)); giveFight($fid, txt5, getFight($fid, txt4)); giveFight($fid, txt4, getFight($fid, txt3)); giveFight($fid, txt3, getFight($fid, txt2)); giveFight($fid, txt2, getFight($fid, txt1)); giveFight($fid, txt1, $newtxt); } and then in another function, i have this code, which is malfunctioning: $mobname = getMob($fighterid[$fornum], mobname); $newtxt2 = "$mobname has died!"; newtxtLine($fid, $newtxt2); and further down: $playername = $namesforgains[0]; $newmsg = "$playername has gained $exp Experience, $credits Credits, and 1 Morale."; newtxtLine($fid, $newmsg); Okay now the problem...and i SWEAR TO YOU, its THESE lines doing it, because I've commented out all the other lines in my code...and its not from a loop or anything...both values ($newtxt2, and $newmsg) write to the database as "$mobname has died!" instead of the seperate strings. I've even commented out the second newtxtLine() statement, and when I do that, it only writes "$mobname has died" once. I've tried everything I can think of.. in case the function was somehow retaining the value I had it set $newtxt = ""; afterward...it still wrote both times as "$mobname has died". I am...completely at a loss here. Anyone have any suggestions? Thanks in advance, Chuck Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/ Share on other sites More sharing options...
Maq Posted May 10, 2009 Share Posted May 10, 2009 Make sure you're echoing out these values before/after you pass them in the function and in each function to make sure they contain the values they're supposed to. There's probably a mix up somewhere where you're assigning two variables the same value. NOTE - Please use around code for proper formatting and syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830812 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 $mobname = getMob($fighterid[$fornum], mobname); That line, is it supposed to be mobname or $mobname? Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830817 Share on other sites More sharing options...
BioRiot Posted May 10, 2009 Author Share Posted May 10, 2009 Sorry this is my first post here, I modified it to show the code properly. Yes I echoed out each line, and commented out each line. $newtxt2 echoed out as "Space Critter has died!"; and $newmsg echoed out as "Chuck has gained 1 Experience, 5 Credits, and 1 Morale."; ...and there are no lines in between those when tested. Same issue. As I said, it makes no sense to me whatsoever. Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830819 Share on other sites More sharing options...
BioRiot Posted May 10, 2009 Author Share Posted May 10, 2009 Ken: No, that line is correct. It retrieves the mob's name properly. :'( Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830822 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 So what if you change the line to - $newtxt2 = $mobname . ' has died!'; Would that work? Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830831 Share on other sites More sharing options...
BioRiot Posted May 10, 2009 Author Share Posted May 10, 2009 Hey Ken, Just tried that out, same deal. Two in a row. I'm considering changing the whole thing over to an associative table but if I still have this same issue I'm going to flip cos there's no reason this shouldn't work and I'm not sure if changing it over will even help. I commented out all lines except those, and changed the values to just names, and I'm having the same problem. My only guess is it has something to do with the 2 functions, but I can't figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830833 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Oh maybe I misunderstood the problem. Is the problem that the strings are being written to the DB twice instead of just once? Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830835 Share on other sites More sharing options...
BioRiot Posted May 10, 2009 Author Share Posted May 10, 2009 For some reason, these 4 lines aren't working. If i comment out line 2, NOTHING gets written to the database...not even for the 2nd newtxtLine(). If I comment out line 4, only 1 copy of $mobname has died is written to the database. On its own, both instances of newtxtLine() are writing "$mobname has died" $newtxt2 = $mobname. " has died!"; newtxtLine($fid, $newtxt2); $newmsg = "$playername has gained '$exp' Experience, '$credits' Credits, and 1 Morale."; newtxtLine($fid, $newmsg); Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830839 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Are there any variables in your include files that could tamper the data? Try echoing the data within that newtxtLine() function to see if they're correct. Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830841 Share on other sites More sharing options...
BioRiot Posted May 10, 2009 Author Share Posted May 10, 2009 Well...I changed everything to associative tables instead...still had the same problem. So, I went back, took out the ' ' in $newmsg = "$playername has gained '$exp' Experience, '$credits' Credits, and 1 Morale."; which I had added before...because I had the problem before I put those in there, and now it works properly. I have no idea what all that was about, but thanks for your help guys. Quote Link to comment https://forums.phpfreaks.com/topic/157559-solved-really-weird-function-problem/#findComment-830863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.