Jump to content

[SOLVED] Help with if else


Darkmatter5

Recommended Posts

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"?

Link to comment
https://forums.phpfreaks.com/topic/156166-solved-help-with-if-else/
Share on other sites

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']))

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.

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":""));
?>

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.