A little PHP help

Discussion in 'PHP' started by JoseYe, Feb 24, 2008.

  1. #1
    I don't know PHP at all. I am self teaching myself, and not even from a tutorial; just from examples from my script.

    However, there are a couple things I need to know if anybody could please help! :)

    You know in registration, when they ask if you are "male" or "female" and you have like a little circle where you can click if your either. What's the code for that?

    Oh and, for the boxes...when you have many options and they can click more than one. Those boxes...

    Thanks!!! :)
     
    JoseYe, Feb 24, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Sounds more like you need to learn HTML. The first is called radio and the second is called... checkboxes. Both are types of input tags in HTML. Here is a tutorial which covers both:
    http://www.w3schools.com/html/html_forms.asp
     
    shallowink, Feb 24, 2008 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    Your Sex?<br />
    Male <input type="radio" name="gender" value="Male"/> &nbsp; Female <input type="radio" name="gender" value="Female"/>

    Then you can get that info in php by using this,

    $gender = $_POST['gender'];

    echo $gender;
     
    HuggyStudios, Feb 24, 2008 IP
  4. JoseYe

    JoseYe Well-Known Member

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Thanks!!! :) Very helpful both the guide and the code.

    A couple of questions though, 1st...I can't use the same variable in other pages, right? I mean I have to put them there so they work there, right?

    And most important...you know when you register and in some websites when they ask you for country and you put US, and (sometimes reloads, others just appears) another box appears to input the state. How do you do that? I tried using the "if" statement, but I don't know exactly how it is.
     
    JoseYe, Feb 24, 2008 IP
  5. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #5
    shallowink, Feb 24, 2008 IP
  6. JoseYe

    JoseYe Well-Known Member

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Thanks again!

    One last question....about the checkboxes....do you know how to make it so that people can choose up to only, for example, 10 options, and at least 5? I've been looking through the tutorial, but couldn't find it :(
     
    JoseYe, Feb 24, 2008 IP
  7. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #7
    Nope. I don't know.
     
    shallowink, Feb 24, 2008 IP
  8. NathanH

    NathanH Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    In regards to the last question:
    You could limit it in PHP (And throw an error if too many or too little were selected), however it would probably be best to use Javascript for this. Try the javascript forum.
     
    NathanH, Feb 24, 2008 IP
  9. JoseYe

    JoseYe Well-Known Member

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #9
    Thanks!

    Yeah, I know...I have a few errors in my code, but it ia only for when they don't put information.

    I knwo if you use "!" before the variable, that's how the error works. What code you need to use to limit though?

    And why would Java be better? Thanks again!
     
    JoseYe, Feb 25, 2008 IP
  10. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #10
    Javascript would be better because it would check before they submitted the page. PHP would check as its processed and would have to redirect back to the form. You would have to count the options for the checkbox and do a check if it was over the limit. like $limit = 5; if($totalCheckboxes >$limit) { error out} else { go }
    Best bet would be to check into using javascript and let php handle success only.
     
    shallowink, Feb 25, 2008 IP
  11. JoseYe

    JoseYe Well-Known Member

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #11
    Do you know a good Javascript guide? like for this?
     
    JoseYe, Feb 25, 2008 IP
  12. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #12
    shallowink, Feb 25, 2008 IP