NameSilo

How to INSERT data from drop down into MySQL DB??

Spaceship Spaceship
Watch

JsteRmX

Established Member
Impact
2
Can anyone please help me do this? I have a registration form that when submitted, only the text fields are inserted and saved in the database. I have one drop down selection menu for users to choose their state. When the form is submitted the state they selected is not inserted into the database, but all the other information is.

let me know if you need to see any more code.

I would really appreciate if someone could give me some pointers, or maybe even code that would work.

here is the code i have for the drop down
Code:
 <td><font size="2" face="Verdana"> <strong>State</strong></font></td>
        <td>
  <select name='State'>
      <option value='Alabama'>Alabama      
      <option value='Alaska'>Alaska      
      <option value='Arizona'>Arizona    
</select>

that code is in a file called form.inc.php with is included in the register.php file. the register.php file includes a file i have called functions.php.

here is the code in register.php that is supposed to "register" the user:
Code:
 user_register ($_POST['username'], $_POST['password'], $_POST['email'], $_POST['firstname'], $_POST['lastname'], $_POST['address'], $_POST['city'], $_POST['state'], $_POST['zip']);

and here is the code in the functions.php file that the above code refers to:
Code:
function user_register($username, $password, $email, $firstname, $lastname, $address, $city, $state, $zip)
{
     // Get a salt using our function
     $salt = generate_salt();

     // Now encrypt the password using that salt
     $encrypted = md5(md5($password).$salt);

     // And lastly, store the information in the database
     $query = "INSERT INTO user (username, password, email, firstname, lastname, address, city, state, zip, salt) values ('$username', '$encrypted', '$email', '$firstname', '$lastname', '$address', '$city', '$state', '$zip', '$salt')";
     $result = mysql_query($query) or die ('Could not create user.');

what is wrong or needs to be fixed? I want the 'state' field in my table to just be populated with the state the user selected in the drop down. seems simple, but i am struggling with this. Thanks for all help in advance!!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
anyone? please i still need help with this.
 
0
•••
Try changing

Code:
 <td><font size="2" face="Verdana"> <strong>State</strong></font></td>
        <td>
  <select name='State'>
      <option value='Alabama'>Alabama      
      <option value='Alaska'>Alaska      
      <option value='Arizona'>Arizona    
</select>

to this

Code:
 <td><font size="2" face="Verdana"> <strong>State</strong></font></td>
        <td>
  <select name='state'>
      <option value='Alabama'>Alabama      
      <option value='Alaska'>Alaska      
      <option value='Arizona'>Arizona    
</select>

Notice how state does not have a cpaital now and this should work
 
0
•••
wow thank you sooo much! that was the problem, so simple to solve but i had no idea that the capitalization mattered. thanks! it works perfectly now, and i have learned something too.

:loveyou:
lol
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back