Jump to content

Recommended Posts

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.'">';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.