ecabrera Posted February 5, 2012 Share Posted February 5, 2012 how would i render this <select name="state" value="<?php echo $state; ?>"> <option>Select a state</option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> <option value="AZ">Arizona</option> <option value="AR">Arkansas</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DE">Delaware</option> <option value="DC">District Of Columbia</option> <option value="FL">Florida</option> <option value="GA">Georgia</option> <option value="HI">Hawaii</option> <option value="ID">Idaho</option> <option value="IL">Illinois</option> <option value="IN">Indiana</option> <option value="IA">Iowa</option> <option value="KS">Kansas</option> <option value="KY">Kentucky</option> <option value="LA">Louisiana</option> <option value="ME">Maine</option> <option value="MD">Maryland</option> <option value="MA">Massachusetts</option> <option value="MI">Michigan</option> <option value="MN">Minnesota</option> <option value="MS">Mississippi</option> <option value="MO">Missouri</option> <option value="MT">Montana</option> <option value="NE">Nebraska</option> <option value="NV">Nevada</option> <option value="NH">New Hampshire</option> <option value="NJ">New Jersey</option> <option value="NM">New Mexico</option> <option value="NY">New York</option> <option value="NC">North Carolina</option> <option value="ND">North Dakota</option> <option value="OH">Ohio</option> <option value="OK">Oklahoma</option> <option value="OR">Oregon</option> <option value="PA">Pennsylvania</option> <option value="RI">Rhode Island</option> <option value="SC">South Carolina</option> <option value="SD">South Dakota</option> <option value="TN">Tennessee</option> <option value="TX">Texas</option> <option value="UT">Utah</option> <option value="VT">Vermont</option> <option value="VA">Virginia</option> <option value="WA">Washington</option> <option value="WV">West Virginia</option> <option value="WI">Wisconsin</option> <option value="WY">Wyoming</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/ Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2012 Share Posted February 5, 2012 What do you mean "render" it? Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314686 Share on other sites More sharing options...
ecabrera Posted February 5, 2012 Author Share Posted February 5, 2012 show the value Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314690 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2012 Share Posted February 5, 2012 The <select> tag doesn't get a value= attribute, BTW. echo $_POST['state']; Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314692 Share on other sites More sharing options...
ecabrera Posted February 5, 2012 Author Share Posted February 5, 2012 ok can i do this <option value="<?php echo $state; ?>"><?php echo $state; ?></option> Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314694 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2012 Share Posted February 5, 2012 I think maybe you should explain what it is you're trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314696 Share on other sites More sharing options...
ecabrera Posted February 5, 2012 Author Share Posted February 5, 2012 ok i making a user account so user can change there state if they ever move to other here which means they can chose form different other states <?php require ("scripts/connect.php"); $query = mysql_query("SELECT * FROM users WHERE email='$email'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $first = $row['firstname']; $last = $row['lastname']; $email = $row['email']; $phone = $row['phone']; $address = $row['address']; $city = $row['city']; $state = $row['state']; $zip = $row['zip']; } else echo "An error occured while connecting to the database."; ?> <div id="userid"> <center><h2><?php echo $first; ?> Account</h2></center> <div id="useraccount"> <?php require ("scripts/connect.php"); if($_POST['savebutton']){ $msg = ""; $first = $_POST['name']; $last = $_POST['last']; $email = $_POST['email']; $phone = $_POST['phone']; $phone = preg_replace('#[^0-9]#i', '', $phone); $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; if($first && $last && $email){ $update = mysql_query("UPDATE users SET firstname='$first',lastname='$last',email='$email', phone='$phone',address='$address',city='$city',state='$state',zip='$zip' WHERE id='$id'"); $msg = "Changes Save"; }else $msg = "YOU MUST FILL IN ALL THREE"; } mysql_close(); ?> <form action="useraccount.php" method="post"> <table> <tr> <td></td> <td><?php echo $msg; ?></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="name" value="<?php echo $first; ?>" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="last" value="<?php echo $last; ?>" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" value="<?php echo $email; ?>" /></td> </tr> <tr> <td>Phone:</td> <td><input type="text" name="phone" maxlength="10" value="<?php echo $phone; ?>" /></td> </tr> <tr> <td>Address:</td> <td><input type="text" name="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city" value="<?php echo $city; ?>" /></td> </tr> <tr> <td>State:</td> <td> <select name="state"> <option>Select a state</option> <option value="<?php echo $state; ?>"><?php echo $state; ?></option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> <option value="AZ">Arizona</option> <option value="AR">Arkansas</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DE">Delaware</option> <option value="DC">District Of Columbia</option> <option value="FL">Florida</option> <option value="GA">Georgia</option> <option value="HI">Hawaii</option> <option value="ID">Idaho</option> <option value="IL">Illinois</option> <option value="IN">Indiana</option> <option value="IA">Iowa</option> <option value="KS">Kansas</option> <option value="KY">Kentucky</option> <option value="LA">Louisiana</option> <option value="ME">Maine</option> <option value="MD">Maryland</option> <option value="MA">Massachusetts</option> <option value="MI">Michigan</option> <option value="MN">Minnesota</option> <option value="MS">Mississippi</option> <option value="MO">Missouri</option> <option value="MT">Montana</option> <option value="NE">Nebraska</option> <option value="NV">Nevada</option> <option value="NH">New Hampshire</option> <option value="NJ">New Jersey</option> <option value="NM">New Mexico</option> <option value="NY">New York</option> <option value="NC">North Carolina</option> <option value="ND">North Dakota</option> <option value="OH">Ohio</option> <option value="OK">Oklahoma</option> <option value="OR">Oregon</option> <option value="PA">Pennsylvania</option> <option value="RI">Rhode Island</option> <option value="SC">South Carolina</option> <option value="SD">South Dakota</option> <option value="TN">Tennessee</option> <option value="TX">Texas</option> <option value="UT">Utah</option> <option value="VT">Vermont</option> <option value="VA">Virginia</option> <option value="WA">Washington</option> <option value="WV">West Virginia</option> <option value="WI">Wisconsin</option> <option value="WY">Wyoming</option> </select> </td> </tr> <tr> <td>Zip Code</td> <td><input type="text" name="zip" maxlength="10" size="8" value="<?php echo $zip; ?>" /></td> </tr> <tr> <td></td> <td><input type="submit" name="savebutton" value="SAVE CHANGES" /></td> </tr> </table> </form> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314697 Share on other sites More sharing options...
trq Posted February 5, 2012 Share Posted February 5, 2012 You should read this. Quote Link to comment https://forums.phpfreaks.com/topic/256444-option/#findComment-1314709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.