#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Undefined index from select tag


    Hello Can anybody help:
    I have this <select> form:

    <select name="Payment type" size="3">
    <option value="Mastercard" selected="selected">MasterCard</option>
    <option value="Visa">Visa</option>
    <option value="Cash">Cash</option>
    </select>

    and I created a value that is using it
    PHP Code:
    echo $_POST['Payment type'];
            switch (isset(
    $_POST['Payment type']) ? $_POST['Payment type'] : NULL) {
                case 
    "Mastercard":
                
    $type="Mastercard";
                break;
                case 
    "Visa":
                
    $type="Visa";
                break;
                case 
    "Cash":
                
    $type="Cash";
                break;
            }
    echo 
    $_POST['Payment type']; 
    and I got Notice: Undefined index: Payment type in C:\xampp\htdocs\WebSite\payment.php on line 12 and sooner on line 24 the same notice
    on line
    PHP Code:
    echo $_POST['Payment type']; 
    so, it means it is never assigned anything. Any help?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    Are you using this code in a place that executes even if the form hasn't been submitted yet?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Are you using this code in a place that executes even if the form hasn't been submitted yet?
    Yes, I need this value for my db butI don't know why it is null cause I chose value in this form
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    How do you expect there to be a value when the form hasn't been submitted?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    How do you expect there to be a value when the form hasn't been submitted?
    I mean I am expecting this: when the user choose one of 3 options it puts this option into value called $_type and execute a program, if the user does not choose anything the default value should go into $_type it that is why I used $_POST but it does for other types but not for select
    and at the beginning I did not include it but I used when the user presses button submit evaluate to these variables a value
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Undefined Index


    The POST variable name should not have a space in it; Use "Payment_type" instead of "Payment type"
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by ArbyVentura
    The POST variable name should not have a space in it; Use "Payment_type" instead of "Payment type"
    Thanks a lot!!! You saved my life!!! Really, I spend 2 days solving this and the answer is so easy!

IMN logo majestic logo threadwatch logo seochat tools logo