Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1050581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:47:29+00:00 2026-05-16T16:47:29+00:00

Basically I am trying to make a simple form that allows the user to

  • 0

Basically I am trying to make a simple form that allows the user to edit data in a table. It pulls the data from the database and uses those variables to prefill the form. Then the user can just edit the info in the form and resubmit the data. The problem is… the state selection is a function that auto creates the drop down box in the form filling it with all the states. I figured if I just add a variable to the beginning of that state array, then the first option in the array will be the state that was already in the database, but it does not work – it just comes up blank. (the first option shown in the drop down is blank, the rest of the list of states do show as it should)

 while ($row = mysql_fetch_array($result)) {
      $id = $row['id'];
      $first = $row['first'];
      $last = $row['last'];
      $city = $row['city'];
      $state = $row['state'];
      $email = $row['email'];
      $bday = $row['bday'];

        function state_selection()
        {
            $str = '<select name="state2">';
            $states = array(
                    "$state","Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii",                                                                                                   "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",                                                                            "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",                                                                            "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia",                                                                            "Wisconsin", "Wyoming"
                );
            foreach ($states as $state_name)
            {
                $str .= '<option value="'.$state_name.'">'.$state_name.'</option>';
            }
            $str .= '</select>';

            return $str;
        }

      $editBlock = '<form method="post" action="./sadd.php">
      <p>First Name: <input name="first2" value="' . $first . '" type="text"  size=13 maxlength=25 /></p>
      <p>Last name: <input name="last2" value="' . $last . '" type="text" size=13 maxlength=25 /></p>
      <p>City:<input name="city2" value="' . $city . '" type="text" size=25 maxlength=50 /></p>
      <p>State: '.state_selection().' </p>
      <p>Email:<input name="email2" value="' . $email . '" type="text" size=50 maxlength=75 /></p>
      <p>Birthday:<input name="bday2" value="' . $bday . '" type="text" size=10 maxlength=10 />(ex 1982-06-26)</p>
      <p><input type="hidden" name="eb" value="ebf" /></p>
      <p><input type="submit" name="submit" value="Update Contact" /></p>
      </form>';

      echo "$editBlock"; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:47:29+00:00Added an answer on May 16, 2026 at 4:47 pm

    $state is not in scope, alter to

     function state_selection($state){
    

    And call like

     state_selection($state);
    

    A more reliable method instead of prepending would be

    '<option value="'.$state_name.'" '.($state_name==$state)?'selected':'').'>'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I've been trying to make a simple Wordpress widget that displays a QR
Basically, I've been trying to make a simple Wordpress widget that displays a QR
I'm trying to make a simple contact form for my website, so I bought
I'm trying to make a simple program that continually displays and updates a label
im trying to make a simple game on cocos2d box2d, its basically got two
Basically, what I'm trying to do is simply make a small script that accesses
I'm trying to make a simple application that loads and runs some classes during
Possible Duplicate: extending from two classes I'm currently trying to make a simple Mod
I'm trying to make a spinner with an array that I retrieve from a
I'm trying to make a pretty simple game and I'm stuck. Basically I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.