1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Do an action based on input value?

Discussion in 'PHP' started by wvccboy, Jun 12, 2007.

  1. #1
    I now have the input script thanks to someone here at DP :D

    In the input (text area), depending on whatever the user enters (for example "demo"), then the input is saved in one MySQL database table. If he enters "demo1" the input is saved in another MySQL database table. Demo and demo1 will be the only options anyway to enter, I may make it multiple choice.

    This way it would be easier to sort out which data is going into the other.

    Thanks!
     
    wvccboy, Jun 12, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    probably be better to use a <select> than an input box. i have found that if you want a user to enter certain data, make them, dont give them a choice. if you want a, or b... dont give them a textbox where they can type "bugg off" give them a <select> box where they can only choose a, or b.
     
    ansi, Jun 12, 2007 IP
  3. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I'm lost, what exactly are you asking?
     
    mrmonster, Jun 12, 2007 IP
  4. dp-user-1

    dp-user-1 Well-Known Member

    Messages:
    794
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Assuming your field name is "input," you would do something like the following:
    $input = $_POST['input'];
    
    switch $input {
    case "demo":
        // Code for this data
        break;
    case "demo1":
        // Code for this data
        break;
    case "demo2":
        // Code for this data
        break;
    default:
        // Code for data that doesn't fit elsewhere
    }
    
    PHP:
     
    dp-user-1, Jun 13, 2007 IP
    wvccboy likes this.
  5. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    in this case radio input will be best because there have to be an option already selected. Also select menu without the Please select.. option
     
    *louie*, Jun 13, 2007 IP
  6. wvccboy

    wvccboy Notable Member

    Messages:
    2,632
    Likes Received:
    81
    Best Answers:
    1
    Trophy Points:
    250
    #6
    Thanks this is what I need. Is it possible to save the input demo into one mysql table, then demo1 be stored into another?

    Thanks
     
    wvccboy, Jun 13, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    yeah, just put the code to insert to the 'demo' table in the case "demo": part. same goes for the rest of it.
     
    ansi, Jun 13, 2007 IP
  8. wvccboy

    wvccboy Notable Member

    Messages:
    2,632
    Likes Received:
    81
    Best Answers:
    1
    Trophy Points:
    250
    #8
    Ok here's the code I have: (I have decided not to use MySQL)

    This here is the script to save the information that was entered.

    As you can see the fwrite out is different, as it is $family, etc.. How can I change that to show the input "case" and then have the script send the data to 2 different files?

    Thanks
     
    wvccboy, Jun 13, 2007 IP
  9. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ProgrammersTalk, Jun 13, 2007 IP
    wvccboy likes this.