Darkmatter5 Posted April 29, 2009 Share Posted April 29, 2009 This is what's passed to the page calc_title.php?id=20&type=games&s=6&i=1&list=coll&collection=yes&trade=yes&unmark=Unmark+for+trade Here's the code executed on the calc_title.php page <?php include('library/config.php'); require_once('library/vein_funcs.php'); ob_start(); session_start(); switch ($_GET['type']) { case "games": $que_colchk=mysql_query("SELECT gs_id FROM game_collections WHERE gs_id='$_GET[id]'") or die(mysql_error()); $que_wlchk=mysql_query("SELECT gs_id FROM game_wishlists WHERE gs_id='$_GET[id]'") or die(mysql_error()); $que_trdchk=mysql_query("SELECT gs_id FROM game_collections WHERE gs_id='$_GET[id]' AND trade_state='1'") or die(mysql_error()); if(isset($_GET['submit'])) { if($_GET['collection']=='yes') { if(mysql_num_rows($que_colchk)==0) { mysql_query("INSERT INTO game_collections (gs_id, member_id, trade_state, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', '0', now())") or die(mysql_error()); } } elseif($_GET['wishlist']=='yes') { if(mysql_num_rows($que_wlchk)==0) { mysql_query("INSERT INTO game_wishlists (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } } if($_GET['trade']=='yes' && !isset($_GET['unmark'])) { mysql_query("UPDATE game_collections SET trade_state='1', fortrade_date=now() WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); } elseif(isset($_GET['unmark'])) { echo "UNMARK"; //mysql_query("UPDATE game_collections SET trade_state='0', fortrade_date=null WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); } } } elseif(isset($_GET['swap'])) { if($_GET['swap']=="Swap to Collection->") { mysql_query("DELETE FROM game_wishlists WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); mysql_query("INSERT INTO game_collections (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } elseif($_GET['swap']=="Swap to Wishlist->") { mysql_query("DELETE FROM game_collections WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); mysql_query("INSERT INTO game_wishlists (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } } break; } //header("Location: http://www.veintrade.com/title.php?type=$_GET[type]&s=$_GET[s]&i=$_GET[i]" .(isset($error)?"&er=$error":"")); ?> Why isn't this printing out "UNMARK"? Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/ Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 In your SQL, put curly braces { } around $_GET['id']. Example: SELECT gs_id FROM game_collections WHERE gs_id='{$_GET[id]}' A better way is to NOT interpolate variables. Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822115 Share on other sites More sharing options...
premiso Posted April 29, 2009 Share Posted April 29, 2009 $_GET['submit'] You do not have "submit" set in your get data. It never gets passed the first if. Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822116 Share on other sites More sharing options...
revraz Posted April 29, 2009 Share Posted April 29, 2009 Indent those nested IFs correctly, so you can see if they are set correctly. It's hard to follow your logic like that. Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822121 Share on other sites More sharing options...
Darkmatter5 Posted April 29, 2009 Author Share Posted April 29, 2009 Okay I updated the indenting as requested. Premiso, the button "Submit" actually initiates this code. Here is the form code <form name='title' method='get' action='calc_title.php'> <input type='hidden' name='id' value='48'> <input type='hidden' name='type' value='games'> <input type='hidden' name='s' value='6'> <input type='hidden' name='i' value='16'> <input type='hidden' name='list' value='coll'> <input type='checkbox' name='collection' value='yes' checked='checked' ><label for='collection'>In my collection</label><br> <input type='checkbox' name='trade' value='yes' ><label for='trade'>Marked for trade</label><p> <input type='submit' name='swap' value='Swap to Wishlist->'><br><input type='submit' name='submit' value='Submit changes'> </form> The last line you can see the two submit buttons "swap" and "submit". The following 3 if/elseif's work fine. if($_GET['collection']=='yes') elseif($_GET['wishlist']=='yes') if($_GET['trade']=='yes' && !isset($_GET['unmark'])) The following is the only one that won't work. elseif(isset($_GET['unmark'])) Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822140 Share on other sites More sharing options...
premiso Posted April 29, 2009 Share Posted April 29, 2009 Okay I updated the indenting as requested. Premiso, the button "Submit" actually initiates this code. In this calc_title.php?id=20&type=games&s=6&i=1&list=coll&collection=yes&trade=yes&unmark=Unmark+for+trade There is no "&submit=Submit Changes". Thus $_GET['submit'] is never being set. I do not know if submit buttons do not pass their value through to get. I never use GET for forums unless it is a search form, so yea. Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822145 Share on other sites More sharing options...
Darkmatter5 Posted April 29, 2009 Author Share Posted April 29, 2009 I realize that's what you meant. Sorry for the confusion. I just can't figure out why the first 3 if's and elseif work, but the last one wont. Is it bad technique to do the if's and elseif's like I did? Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822164 Share on other sites More sharing options...
Darkmatter5 Posted April 29, 2009 Author Share Posted April 29, 2009 Figured it out had the $_GET['unmark'] code nested when it shouldn't have been. Premiso, thanks for the comment! That was the issue. <?php include('library/config.php'); require_once('library/vein_funcs.php'); ob_start(); session_start(); switch ($_GET['type']) { case "games": $que_colchk=mysql_query("SELECT gs_id FROM game_collections WHERE gs_id='$_GET[id]'") or die(mysql_error()); $que_wlchk=mysql_query("SELECT gs_id FROM game_wishlists WHERE gs_id='$_GET[id]'") or die(mysql_error()); $que_trdchk=mysql_query("SELECT gs_id FROM game_collections WHERE gs_id='$_GET[id]' AND trade_state='1'") or die(mysql_error()); if(isset($_GET['submit'])) { if($_GET['collection']=='yes') { if(mysql_num_rows($que_colchk)==0) { mysql_query("INSERT INTO game_collections (gs_id, member_id, trade_state, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', '0', now())") or die(mysql_error()); } } elseif($_GET['wishlist']=='yes') { if(mysql_num_rows($que_wlchk)==0) { mysql_query("INSERT INTO game_wishlists (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } } if($_GET['trade']=='yes') { mysql_query("UPDATE game_collections SET trade_state='1', fortrade_date=now() WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); } } elseif(isset($_GET['unmark'])) { mysql_query("UPDATE game_collections SET trade_state='0', fortrade_date=null WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); } elseif(isset($_GET['swap'])) { if($_GET['swap']=="Swap to Collection->") { mysql_query("DELETE FROM game_wishlists WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); mysql_query("INSERT INTO game_collections (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } elseif($_GET['swap']=="Swap to Wishlist->") { mysql_query("DELETE FROM game_collections WHERE gs_id='$_GET[id]' AND member_id='$_SESSION[member_id]'") or die(mysql_error()); mysql_query("INSERT INTO game_wishlists (gs_id, member_id, add_date) VALUES ('$_GET[id]', '$_SESSION[member_id]', now())") or die(mysql_error()); } } break; } header("Location: title.php?type=$_GET[type]&s=$_GET[s]&i=$_GET[i]" .(isset($error)?"&er=$error":"")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/#findComment-822170 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.