sandrob57 Posted March 1, 2007 Share Posted March 1, 2007 $target_id = 3; $result_war = dbquery("SELECT * FROM fusion_wars WHERE a_id='".$user_id."' AND d_id='".$target_id."'"); if (dbrows($result_war) > 0 && dbrows($result_war) < 2){ $data = dbarray($result_war); } echo "$data['a_turns']"; $data['a_turns'] is displaying data from where target_id = 2, not 3. It basically isnt pulling data correctly. Why? Ask if you need more info. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/ Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 I would try running that query manually. Or at least printing out the query before executing it. In this type of situation, it's usually the wrong query, or the data in the database is not what you thought it was. The other common situation is using the wrong result variable, but that looks ok for your script. I would check that you are actually getting rows back though.. have an "if (dbrows($result_war) == 0) { print "No rows returned??<br>"; }" Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196613 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 I would try running that query manually. Or at least printing out the query before executing it. In this type of situation, it's usually the wrong query, or the data in the database is not what you thought it was. The other common situation is using the wrong result variable, but that looks ok for your script. I would check that you are actually getting rows back though.. have an "if (dbrows($result_war) == 0) { print "No rows returned??<br>"; }" It returns the rows. Sadly. This has been driving me crazy for 5 hours. Something in this script is just giving me a hard time. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196616 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Does it return the rows with the data you are expecting? You can always track down a bug by tracking the data backwards until you find the point at which it changes from being correct to incorrect. That point is exactly where your bug is. Right now you know that $data['a_turns'] is incorrect. So go back through your code printing out values until you find where it becomes correct. Then you have the exact location of your bug Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196618 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 try and see what row is returned $result_war = dbquery("SELECT * FROM `fusion_wars` WHERE `a_id`='".$user_id."' AND `d_id`=".$target_id." LIMIT 0 , 1"); it may provide some insight Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196619 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 ok, there are two rows in the database table. Once is my username = 1 and one is target user name = 2. The other is 1 and 3, repectively. $result_war = dbquery("SELECT * FROM fusion_wars WHERE a_id='".$user_id."' AND d_id='".$target_id."'"); if (dbrows($result_war) > 0 && dbrows($result_war) < 2){ $data = dbarray($result_war); } I have $target_id defined in the url as 2. Why is pulling the data for 3? Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196621 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 can you post the table, Fields and data, or the sql to create them. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196623 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Can you add the following inside the if statement for me? var_dump($data); And then show us the output. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196626 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 Database Table: fusion_wars Fields: war_id a_id d_id war_start a_turns d_turns a_peace d_peace a_update d_update There are the (only) two rows: Row 1: 79, 1, 2, var, 4, 4, 0, 0, var, var Row 2: 78, 1, 3, var, 8, 1, 0, 0, var, var (var is just a datestamp) edit: var_dump($data); coming soon edit2: here it is array(10) { ["war_id"]=> string(2) "78" ["a_id"]=> string(1) "1" ["d_id"]=> string(1) "3" ["war_start"]=> string(10) "1172512146" ["a_turns"]=> string(1) "8" ["d_turns"]=> string(1) "1" ["a_peace"]=> string(1) "0" ["d_peace"]=> string(1) "0" ["a_update"]=> string(10) "1172710572" ["d_update"]=> string(10) "1172710562" } 8 Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196630 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 can you please try this line $result_war = dbquery("SELECT * FROM `fusion_wars` WHERE `a_id`='".$user_id."' AND `d_id`=".$target_id." LIMIT 0 , 1"); as it should work! Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196632 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 It appears the data from the database is correct. It is for target_id 3. Why do you think that it is incorrect? Edit: If you look in the var_dump() output, you will see that d_id is set to 3, and the other data is all for the matching row from the db. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196633 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 It appears the data from the database is correct. It is for target_id 3. Why do you think that it is incorrect? $target_id is set to 2 in the page URL. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196635 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 And what is this doing just before your query? $target_id = 3; Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196637 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 And what is this doing just before your query? $target_id = 3; No that isn't there on the actual page. This is the entire actualy page. display.php?view=ground&wartype=offensive&target_id=2 <?php if ($page_id == 21){ if ($view == 'ground' || $view == 'air' || $view == 'missile'){ include "".BASEDIR."wars/combat/".$view.".php"; }else{ redirect("".BASEDIR."news.php"); } }else{ redirect("".BASEDIR."news.php"); } ?> Which calls: <?php //Base variables $user_id = $userdata['user_id']; $target_id = $target_id; $wartype = $wartype; if ($wartype != '' && $user_id > 0 && $target_id > 0){ //Do the math if ($wartype == 'offensive'){ // offense offense offense $check = 'true'; $result_war = dbquery("SELECT * FROM `fusion_wars` WHERE `a_id`='".$user_id."' AND `d_id`=".$target_id.""); if (dbrows($result_war) > 0 && dbrows($result_war) < 2){ $data = dbarray($result_war); echo "".$data['a_turns'].""; $your_turns = $data['a_turns']; $result_1 = dbquery("SELECT * FROM fusion_users WHERE user_id='".$data['d_id']."'"); if (dbrows($result_1)) { $target = dbarray($result_1); } else { redirect("index.php"); } } else { $check = 'false'; } if ($check != 'true') { redirect("".BASEDIR."index.php"); } }elseif ($wartype == 'defensive'){ // defense defense defense //coming soon }else{ redirect("".BASEDIR."news.php"); //escape } }else{ redirect("".BASEDIR."news.php"); //escape } //Checks, Checks, and Checks if($userdata['c_war'] == 'no' || $target['c_war'] == 'no'){ $check = 'false'; } if($userdata['user_id'] == $target['user_id']){ $check = 'false'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196638 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Ok, here's some steps which will fix your problem. First, echo out the query before running it, like this: $sql = "SELECT * FROM `fusion_wars` WHERE `a_id`='".$user_id."' AND `d_id`=".$target_id." LIMIT 0 , 1"; print "About to run $sql<br>"; $result_war = dbquery($sql); Then, after you've fetched the data, print it out: $data = dbarray($result_war); print "<pre>"; var_dump($data); print "</pre>"; Do they match up? Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196640 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 Ok, here's some steps which will fix your problem. First, echo out the query before running it, like this: $sql = "SELECT * FROM `fusion_wars` WHERE `a_id`='".$user_id."' AND `d_id`=".$target_id." LIMIT 0 , 1"; print "About to run $sql<br>"; $result_war = dbquery($sql); Then, after you've fetched the data, print it out: $data = dbarray($result_war); print "<pre>"; var_dump($data); print "</pre>"; Do they match up? I found the problem.. On the url, $target_id is set to 2. before I even do the sql lookup, i echoed out $target_id - that stubborn bastard is set at 3. I'm gonna look if anything could have effected, but so far there is literaly no code that could. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196641 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 It'll be there somewhere A simple method to find where is to print $target_id out at various stages throughout the script. Somewhere it will change from 2 to 3. Or it may even be 3 from the very start. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196643 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 Ok what the hell. This is the url. viewpage.php?page_id=21&view=ground&wartype=offensive&target_id=2 See target ID? Well for some reason, even after I remove ALL THE CODE BEFORE IT it still sets target_id to 3. Are there some ground rules im breaking with calling in url variables? Can you use them in with an included script? Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196644 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 It'll be there somewhere A simple method to find where is to print $target_id out at various stages throughout the script. Somewhere it will change from 2 to 3. Or it may even be 3 from the very start. I put echo "2) $target_id"; on every other line. It's 3 the entire time except in the URL. EDIT: sure enough the problem lies in my subheader.php file, which uses a target_id variable........I feel so smart for wasting 5 hours on this. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196645 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Ok.. so it's 3 right from the start. Well that url looks fine to me. How about $_GET['target_id'], is that set to 2 or 3? Edit: 5 hours well-spent.. you won't make the same mistake again Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196646 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 K now when I do this: $result_war = "SELECT * FROM fusion_wars WHERE 'a_id'='$user_id' AND 'd_id'='$target_id'"; $data = dbarray($result_war); var_dump($data); I get this for the dump: bool(false) I am 100% sure that target_id is 2 and user_id is 1 Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196666 Share on other sites More sharing options...
rcorlew Posted March 1, 2007 Share Posted March 1, 2007 You could be running into some cache(ing) problems on your local pc. One thing I do is to unset($var) before I reset it. Let's say someone tried a failed login, I have had problems with it just reposting the same data even though it is supposed to post new data. Web browsers do weird things depending on how each user has them set. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196675 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 I added unset($result_war); and unset($data); before it, and still no luck Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196677 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Shouldn't that be `a_id`, not 'a_id' ? Edit: You should edit dbarray() so it checks for errors. Otherwise you will have more problems like this in future. Edit2: Where's the call to mysql_query()? What I meant above is that you should check for errors from mysql_query() Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196682 Share on other sites More sharing options...
sandrob57 Posted March 1, 2007 Author Share Posted March 1, 2007 Shouldn't that be `a_id`, not 'a_id' ? Edit: You should edit dbarray() so it checks for errors. Otherwise you will have more problems like this in future. The `a_id` made no difference. The array dumps as NULL. Quote Link to comment https://forums.phpfreaks.com/topic/40647-solved-troubling-script/#findComment-196685 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.