SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    A form variable is not being inserted into DB

    I have a form field called, "member" that is no longer being inserted into the DB when the user clicks submit. Can someone help me see what I'm missing? Here are the relevant bits of code:

    When viewing the form:

    PHP Code:
    <select name="member" class=form id="member">
    <
    option value="No">No</option>
    <
    option value="Customer">Customer</option>
    <
    option value="Distributor">Distributor</option>
    </
    select
    When processing the form:

    PHP Code:
    $member         $_REQUEST['member'];

    mysql_query ("INSERT INTO users (firstname, lastname, member, membernumber) VALUES (
    '
    $firstname', 
    '
    $lastname', 
    '
    $member',
    '
    $membernumber')"); 
    Is there anything wrong with what I have?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SitePoint Zealot Cute Tink's Avatar
    Join Date
    Apr 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is $_REQUEST['member'] being populated? Have you echo'd $member to make sure the value is making it through?

    Also, are you sanitizing the variables before they get to the query, like using mysql_real_escape_string()?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <select name="member" class=form id="member">
     
    <option value="No">No</option>
     
    <option value="Customer">Customer</option>
     
    <option value="Distributor">Distributor</option>
     
    </select>

    Your html has broken tags, try this

    <select name="member" class="form" id="member">

    <option value="No">No</option>

    <option value="Customer">Customer</option>

    <option value="Distributor">Distributor</option>

    </select>

  4. #4
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cute Tink View Post
    Is $_REQUEST['member'] being populated? Have you echo'd $member to make sure the value is making it through?
    Ok, when I echo the variable it appears that its not making it through. The weird thing is that my site has been running for 7 years and I don't think I've messed with this variable. All other variables are making it through. Any ideas on what I'm overlooking?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If your form uses the POST method, then access the variable with $_POST['member'].

    If your form uses the GET method, then access the variable with $_GET['member'].

  6. #6
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    If your form uses the POST method, then access the variable with $_POST['member'].

    If your form uses the GET method, then access the variable with $_GET['member'].

    I changed from using _REQEST to _POST and still $member is not being pulled through. Any other thoughts?

    Thanks
    Convert your dollars into silver coins. www.convert2silver.com

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Need to see the full code for the form.

  8. #8
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Need to see the full code for the form.
    Ok, I got it to work by adding the variable to the session after retrieving it using POST, like this:

    PHP Code:
    $member  $_POST['member'];

    $_SESSION['member'] = $_POST['member']; 
    Can anyone explain why this is the only variable on my form that requires this? Ugh, very frustrating.
    Convert your dollars into silver coins. www.convert2silver.com

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    again, without seeing your code, all I can do is point and say 'look, it works'.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •