recieve data from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dbarron87
Forum Newbie
Posts: 16
Joined: Wed Apr 20, 2011 8:12 pm

recieve data from database

Post by dbarron87 »

Hello all and thanks for looking.

i am currently in the process of trying to create a change address form linked to the database


on the registration form it has a drop down of country listed with countries from a database

how would i recive this data as a drop down again but with the chosen option selected?

and then how would i get the drop down to update the form from that current page too?

Many thanks in advance

This is the code for the file in (user_reg_inc.php)

Code: Select all

$country=$_POST[cbocountry];

if(empty($country))
	{
   $err_city_sql="select * from error_message where err_id=23";
   $err_city_res=mysql_query($err_city_sql);
   $err_city_row=mysql_fetch_array($err_city_res);
   $err_country=$err_city_row[err_msg];
   $err_flag=1;
	}


 $sql.="country";
$sql.="''$country";

$state_sql="select * from state_master where country_id=38 ";
$state_res=mysql_query($state_sql);
$county_sql="select * from county_master";
$county_res=mysql_query($county_sql);
$country_sql="select * from country_master";
$country_res=mysql_query($country_sql);



This is code from (user_reg.tpl)

Code: Select all

<? if(!empty($err_country))
 {
 ?>
<tr><td>&nbsp;</td><td><a href="user_reg.php#cbocountry">country</a> - <?= $err_country; ?></td></tr>
<?
}
?>

 <td>
 <? if(!empty($err_country))
 {
 ?>
 <img src="images/warning_9x10.gif">&nbsp;<font size=2 color=red><?= $err_country ?></font>
 <br>
 <font size=2 color=red>Country</font></b>
 <?
  }
  else
  {
 ?>
 <span class="style2">
 <font size=2>Country </font></b></span><font color="#FF0000">*</font>
 <?
 }
 ?> </td>
 </tr>


<td><select name=cbocountry id="txtzipcode">
 <option value=0>Select</option>
   <?
  $country_sql="select * from country_master";
  $country_res=mysql_query($country_sql);
  while($country_row=mysql_fetch_array($country_res))
 {
  if(trim($country_row['country_id'])==trim($country))
  {
   ?>
  <option value="<?= $country_row['country_id'] ?>" selected><?= $country_row['country']?></option>
  <?
  }
  else
  {
  ?>
  <option value="<?= $country_row['country_id'] ?>"><?= $country_row['country']?></option>
  <?
  }
  }
  ?>
  </select>
  </td>
  </tr>
 <tr><td>


the whole drop down form does seem to work, but am looking to have a page where as if a user changes address it will show there current option and allow them to change it.

Would there be a way to use the above code and echo that some how?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: recieve data from database

Post by Jade »

I believe this is what you're looking for: http://roshanbh.com.np/2008/01/populate ... d-php.html
Post Reply