Simple If Statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff  Vaccaro

    Simple If Statement

    How come this doesn't work?

    What am I doing wrong?

    $type = $_GET['functionType'];

    if ($type == 'Add'){
    $AddSQL = "INSERT INTO...";
    echo $AddSQL;
    }elseif ($type == 'Update'){
    $UpdateSQL = "Update ...";
    echo $UpdateSQL;
    }elseif ($type == 'Delete'){
    $DelSQL = "DELETE FROM ...";
    echo $DelSQL;
    }

    Thanks

  • Marcin Dobrucki

    #2
    Re: Simple If Statement


    print_r($_GET);

    See if 'functionType' is set, and one of those values. You could
    also do:

    if ( isset($_GET['functionType']) ) {
    $type = $_GET['functionType'];
    // the rest of the if stuff
    }
    else {
    die ("Error, functionType is not in GET");
    }


    /m

    Jeff Vaccaro wrote:
    How come this doesn't work?
    >
    What am I doing wrong?
    >
    $type = $_GET['functionType'];
    >
    if ($type == 'Add'){
    $AddSQL = "INSERT INTO...";
    echo $AddSQL;
    }elseif ($type == 'Update'){
    $UpdateSQL = "Update ...";
    echo $UpdateSQL;
    }elseif ($type == 'Delete'){
    $DelSQL = "DELETE FROM ...";
    echo $DelSQL;
    }
    >
    Thanks
    >

    Comment

    • Janwillem Borleffs

      #3
      Re: Simple If Statement

      Jeff Vaccaro wrote:
      How come this doesn't work?
      >
      What am I doing wrong?
      >
      $type = $_GET['functionType'];
      >
      Print $type and check the case; 'add' and 'Add' are two different things the
      way you compare them.

      If the case indeed is the problem try the following function:




      JW


      Comment

      • Jeff  Vaccaro

        #4
        Re: Simple If Statement

        Apparently there was a rogue space in the $_GET. I trimmed that and
        now it appears to be working!

        Thanks.


        Janwillem Borleffs wrote:
        Jeff Vaccaro wrote:
        How come this doesn't work?

        What am I doing wrong?

        $type = $_GET['functionType'];
        >
        Print $type and check the case; 'add' and 'Add' are two different things the
        way you compare them.
        >
        If the case indeed is the problem try the following function:
        >

        >
        >
        JW

        Comment

        • Sebastian Scherhans

          #5
          Re: Simple If Statement

          Print $type and check the case; 'add' and 'Add' are two different things the
          way you compare them.
          you could also use strtolower to have just lower cases to compare

          Comment

          • william

            #6
            Re: Simple If Statement

            On Tue, 02 Jan 2007 05:47:20 -0800, Jeff Vaccaro wrote:
            How come this doesn't work?
            >
            What am I doing wrong?
            >
            $type = $_GET['functionType'];
            >
            if ($type == 'Add'){
            $AddSQL = "INSERT INTO...";
            echo $AddSQL;
            }elseif ($type == 'Update'){
            $UpdateSQL = "Update ...";
            echo $UpdateSQL;
            }elseif ($type == 'Delete'){
            $DelSQL = "DELETE FROM ...";
            echo $DelSQL;
            }

            you should make your code more readable (for yourself)
            have a look on switch/case/break.

            Comment

            • Curtis

              #7
              Re: Simple If Statement

              Make sure you declare your variables first, especially if
              register_global s is on. A client could potentially modify/create
              variables and contents arbitrarily.

              See: http://php.net/register_globals

              On Jan 2, 8:12 am, william <b...@no.spamwr ote:
              On Tue, 02 Jan 2007 05:47:20 -0800, Jeff Vaccaro wrote:
              How come this doesn't work?
              >
              What am I doing wrong?
              >
              $type = $_GET['functionType'];
              >
              if ($type == 'Add'){
              $AddSQL = "INSERT INTO...";
              echo $AddSQL;
              }elseif ($type == 'Update'){
              $UpdateSQL = "Update ...";
              echo $UpdateSQL;
              }elseif ($type == 'Delete'){
              $DelSQL = "DELETE FROM ...";
              echo $DelSQL;
              }you should make your code more readable (for yourself)
              have a look on switch/case/break.

              Comment

              Working...