Jump to content

Recommended Posts

Ok here is what im trying to do:

1. drop down list pulled from mysql database.

2. after you select the name in the drop down list

below the drop down list it should show the address.

3. if you select another name in the drop down list it should update the address

Here is the code what am I doing wrong? the drop down menu works but it doesnt post the address

thanks,

Randy

 

     <?php
	//Get Name/Company out of database
$db = mysql_connect("ip","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");  
	$query="SELECT * FROM `customers`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\"></span><select name=\"name\" id=\"name\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$address=mysql_result($result,$techname,"address");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";


          echo "<p>Address:"; 
          echo "$address";
	//Get address out of database


       ?>

Your code has no code in it to process the form submission and get the correct address to display. Any address it is currently displaying is just the address from the last row that was fetched when you built the drop-down menu. Building the form and processing the form are two separate operations and you need code to perform each operation.

 

If you want the address to be updated without refreshing the whole page, yes you do need to use javascript (AJAX.) If you don't care if the page refreshes, you can just submit the form normally and let the whole page redisplay. Which method did whoever assigned this want you to use?

 

And if you want the form to automatically submit when you pick a different selection in your drop-down, you will need to use an onchange event.

 

That's also not all of your form and probably won't submit anything anyway. What is your full code on the page?

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.