rmelino Posted July 25, 2009 Share Posted July 25, 2009 Hello, I am having trouble getting a drop down working on my members page. I'd like to have a drop down which includes the names of cities for the user to pick. (i don't need the cities pre populated from the db, they will just be static) All i need is for the drop down to appear and when the user selects their city and hits update it gets inserted into the db. In my code below, i've got name, address, and city set up but each of them are just with text boxes at this point. I included my functions.php file below too so you can see the function used for the text box. I am assuming i will need to add something similar to functions.php that corresponds to a dropdown function but i don't know what that function would be. Thanks for looking at this! <?php include ('functions.php'); include ('config.php'); ?> <?php $username = $_SESSION['s_username']; if (!$_POST['update']) { } else { $name = typography($_POST['name']); $address = typography($_POST['address']); $city = typography($_POST['city']); // prevent injection $name = mysql_real_escape_string($name); $address = mysql_real_escape_string($address); $city = mysql_real_escape_string($city); if (trim($name) == ""){ $sql = "SELECT * FROM `Users` LIMIT 0 , 30"; } else { $update = @mysql_query("UPDATE Users SET name = '$name' WHERE username = '$username' LIMIT 1"); if ($update) echo '<p class="updatemsg">» Name Successfully Updated</p>'; else echo '<p class="updatemsgerror">Error Updating Name</p>'; } } if (trim($address) == ""){ $sql = "SELECT * FROM `Users` LIMIT 0 , 30"; } else { $update = @mysql_query("UPDATE Users SET address = '$address' WHERE username = '$username' LIMIT 1"); if ($update) echo '<p class="updatemsg">Address Successfully Updated</p>'; else echo '<p class="updatemsgerror">Error Updating Address</p>'; } if (trim($city) == ""){ $sql = "SELECT * FROM `Users` LIMIT 0 , 30"; } else { $update = @mysql_query("UPDATE Users SET city = '$city' WHERE username = '$username' LIMIT 1"); if ($update) echo '<p class="updatemsg">City Successfully Updated</p>'; else echo '<p class="updatemsgerror">Error Updating City</p>'; } switch($_GET['change']){ case 'location': $query="SELECT name FROM `Users` WHERE username = '$username' LIMIT 1"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) { $namecurrent=$row->name; } echo '<p class="updatemsg">Your Name Currently Reads:</p> <div id="current"> <p class="current">'.$namecurrent.'</p> </div> <form method="post"> <table width="50%"> <tr><td>Edit Your State in the Box Below:'.form_input(text,name,$name, 50, 80).'</td></tr> <tr><td>'.form_button(submit, update, Update).'</td></tr> </table> </form>'; $query="SELECT address FROM `Users` WHERE username = '$username' LIMIT 1"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) { $addresscurrent=$row->address; } echo '<p class="updatemsg">Your Street Address Currently Reads:</p> <div id="current"> <p class="current">'.$addresscurrent.'</p> </div> <form method="post"> <table width="50%"> <tr><td>Edit Your Street Address in the Box Below:'.form_input(text,address,$address, 50, 80).'</td></tr> <tr><td>'.form_button(submit, update, Update).'</td></tr> </table> </form>'; $query="SELECT city FROM `Users` WHERE username = '$username' LIMIT 1"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) { $citycurrent=$row->city; } echo '<p class="updatemsg">Your City Currently Reads:</p> <div id="current"> <p class="current">'.$citycurrent.'</p> </div> <form method="post"> <table width="50%"> <tr><td>Edit Your City in the Box Below:'.form_input(text,city,$city, 50, 80).'</td></tr> <tr><td>'.form_button(submit, update, Update).'</td></tr> </table> </form>'; break; } ?> functions.php: <?php //Input Field Function function form_input ($type='', $name='', $value='', $size='', $max='') { return '<input class="textfield" type="'.$type.'" size="'.$size.'" maxlength="'.$max.'" name="'.$name.'" value="'.$value.'">'; } //Button Function function form_button ($type='',$name='',$value='') { return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167403-problem-inserting-data-from-drop-down-into-mysql-table/ 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.