Jump to content

Recommended Posts

Hi,

 

I have this form which has got all these drop down boxes which has values built in the html form, once selected they are all sent to the database table to be stored only when the authentication is done and for that record only.

 

I am also using the same form to retrieve information from the database and display back to the form. The problem is i am not able to display data retrieved from the database into the drop down boxes. Can someone please help me the code please.

 

Thanks much for the help.

 

 

<?php
include 'init.php';

if (!is_authed())
{
        header("Location: http://xxxx/wewewe/wee.ph");
        exit;
}
$ID = $_SESSION['ID'];

$results = mysql_query("SELECT * FROM `WorkExperience` WHERE ID=$ID");
$row = mysql_num_rows($results);
if($row == 0)
{
        mysql_query("INSERT INTO `WorkExperience` (ID) VALUES ('$ID')");
}

if($_POST['save'] || $_POST['next'])
{ 



$CountryOfEmployment = $_POST['CountryOfEmployment'];
$CommencementDate = $_POST['CommencementDate'];
$CommencementMonth = $_POST['CommencementMonth'];
$CommencementYear = $_POST['CommencementYear'];



$query = "UPDATE `WorkExperience` SET CountryOfEmployment='$CountryOfEmployment', CommencementDay='$CommencementDay', CommencementMonth='$CommencementMonth', CommencementYear='$CommencementYear' WHERE ID=$ID";


mysql_query($query);
}

if($_POST['next'])
{
        header("Location: gotonextpage.php");
        exit();
}

$query = "SELECT * FROM `WorkExperience` WHERE ID=$ID";
$results = mysql_query($query);
$data = mysql_fetch_array($results);


$CountryOfEmployment = $data['CountryOfEmployment'];
$CommencementDay = $data['CommencementDay'];
$CommencementMonth = $data['CommencementMonth'];
$CommencementYear = $data['CommencementYear'];


?>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<TITLE>Graduate Admission System (Research Programme)</TITLE>

<link href="CSS/GraduateProgram.css" rel="stylesheet" type="text/css">

</head>

<body bgcolor="#FFFFFF" topmargin="0">
<br>
  <br>


<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="pg6.php"> 
  <TABLE  border=0 ALIGN="center" cellpadding = 3 cellspacing = 0  width="1000" style="border:1px solid #999999;">

<TR>
<td width="68%" align="left" class="BodyText">

			Country of Employment  


			 :	</td>
<td width=68% align="left" class="BodyText">
<select name="CountryOfEmployment" class="BodyText" style="color: 000000 ; font-weight: bold"
value="<?=$CountryOfEmployment?>" id="CountryOfEmployment">
  <option> 
    <option
>AFGHANISTAN
      <option
>ALBANIA
        <option
>ALGERIA
        <option
>AMERICAN SAMOA
        <option
>ANDORRA
        <option
>ANGOLA
        <option
>ANTIGUA
        <option
>ARGENTINA
        <option
>ARMENIA 
        <option
>AUSTRALIA
        <option
>AUSTRIA
        <option
>AZERBAIJAN
        <option
>BAHAMAS
        <option
>BAHRAIN
        <option
>BANGLADESH
        <option
>BARBADOS
        <option
>BELARUS
        <option
>BELGIUM
        <option
>BELIZE
        <option
>BENIN
        <option
>BHUTAN
        <option
>BOLIVIA
        <option
>BOSNIA
        <option
>BOTSWANA
        <option
>BRAZIL
        <option
>BRITISH NATIONAL OVERSEAS
        <option
>BRUNEI
        <option
>BRUNEI PR
        <option
>BULGARIA
        <option
>BURKINA FASO
        <option
>BURUNDI
        <option
>CAMBODIA
        <option
>CAMEROON
        <option
>CANADA
        <option
>CAPE VERDE
        <option
>CENTRAL AFRICAN REP
        <option
>CHAD
        <option
>CHILE
        <option
>CHINA
        <option
>COLOMBIA
        <option
>COMOROS
        <option
>CONGO
        <option
>COOK ISLANDS
        <option
>COSTA RICA
        <option
>CROATIA
        <option
>CUBA
        <option
>CYPRUS
        <option
>CZECH REPUBLIC
        <option
>DENMARK
        <option
>DJIBOUTI
        <option
>DOMINICA
        <option
>DOMINICAN REP
        <option
>EAST TIMOR
        <option
>ECUADOR
        <option
>EGYPT
        <option
>EL SALVADOR
        <option
>EQUATORIAL GUINEA
        <option
>ERITREA
        <option
>ESTONIA
        <option
>ETHIOPIA
        <option
>FIJI
        <option
>FINLAND
        <option
>FRANCE
        <option
>FRENCH GUIANA
        <option
>FRENCH POLYNESIA
        <option
>GABON
        <option
>GAMBIA
        <option
>GEORGIA
        <option
>GERMANY
        <option
>GHANA
        <option
>GREECE
        <option
>GRENADA
        <option
>GUADELOUPE
        <option
>GUAM
        <option
>GUATEMALA
        <option
>GUINEA
        <option
>GUINEA-BISSAU
        <option
>GUYANA
        <option
>HAITI
        <option
>HONDURAS
        <option
>HONG KONG
        <option
>HUNGARY
        <option
>ICELAND
        <option
>INDIA
        <option
>INDONESIA
        <option
>IRAN
        <option
>IRAQ
        <option
>IRELAND
        <option
>ISRAEL
        <option
>ITALY
        <option
>IVORY COAST
        <option
>JAMAICA
        <option
>JAPAN
        <option
>JORDAN
        <option
>KAZAKHSTAN
        <option
>KENYA
        <option
>KIRIBATI
        <option
>KUWAIT
        <option
>KYRGYZSTAN
        <option
>LAOS
        <option
>LATVIA
        <option
>LEBANON
        <option
>LESOTHO
        <option
>LIBERIA
        <option
>LIBYA
        <option
>LIECHTENSTEIN
        <option
>LITHUANIA
        <option
>LUXEMBOURG
        <option
>MACAU
        <option
>MACEDONIA
        <option
>MADAGASCAR
        <option
>MALAWI
        <option
>MALAYSIA
        <option
>MALAYSIA PR
        <option
>MALDIVES
        <option
>MALI
        <option
>MALTA
        <option
>MARSHALL ISLANDS
        <option
>MARTINIQUE
        <option
>MAURITANIA
        <option
>MAURITIUS
        <option
>MEXICO
        <option
>MICRONESIA
        <option
>MONACO
        <option
>MONGOLIA
        <option
>MOROCCO
        <option
>MOZAMBIQUE
        <option
>MYANMAR
        <option
>NAMIBIA
        <option
>NAURU
        <option
>NEPAL
        <option
>NETHERLANDS
        <option
>NETHERLANDS ANTILLES
        <option
>NEW CALEDONIA
        <option
>NEW ZEALAND
        <option
>NICARAGUA
        <option
>NIGER
        <option
>NIGERIA
        <option
>NIUE ISLAND
        <option
>NORTH KOREA
        <option
>NORTHERN IRELAND
        <option
>NORWAY
        <option
>OMAN
        <option
>OTHERS
        <option
>PAKISTAN
        <option
>PALAU
        <option
>PALESTINE
        <option
>PANAMA
        <option
>PAPUA NEW GUINEA
        <option
>PARAGUAY
        <option
>PERU
        <option
>PHILIPPINES
        <option
>PITCAIRN ISLAND
        <option
>POLAND
        <option
>PORTUGAL
        <option
>PUERTO RICO
        <option
>QATAR
        <option
>REUNION
        <option
>ROMANIA
        <option
>RUSSIA
        <option
>RWANDA
        <option
>SAO TOME AND PRINCIPE
        <option
>SAUDI ARABIA
        <option
>SENEGAL
        <option
>SEYCHELLES
        <option
>SIERRA LEONE
        <option
>SINGAPORE
        <option
>SINGAPORE PR
        <option
>SLOVAK REPUBLIC
        <option
>SLOVENIA
        <option
>SOLOMON ISLANDS
        <option
>SOMALIA
        <option
>SOUTH AFRICA
        <option
>SOUTH KOREA
        <option
>SOUTH YEMEN
        <option
>SPAIN
        <option
>SRI LANKA
        <option
>ST. LUCIA
        <option
>ST. VINCENT
        <option
>STATELESS
        <option
>SUDAN
        <option
>SURINAME
        <option
>SWAZILAND
        <option
>SWEDEN
        <option
>SWITZERLAND
        <option
>SYRIA
        <option
>TAIWAN
        <option
>TAJIKISTAN
        <option
>TANZANIA
        <option
>THAILAND
        <option
>TOGO
        <option
>TOKELAU ISLANDS
        <option
>TONGA
        <option
>TRINIDAD AND TOBAGO
        <option
>TUNISIA
        <option
>TURKEY
        <option
>TUVALU
        <option
>UGANDA
        <option
>UKRAINE
        <option
>UNITED ARAB EMIRATES
        <option
>UNITED KINGDOM
        <option
>UNITED STATES
        <option
>URUGUAY
        <option
>UZBEKISTAN
        <option
>VANUATU
        <option
>VENEZUELA
        <option
>VIETNAM
        <option
>WALLIS AND FUTUNA
        <option
>WESTERN SAHARA
        <option
>YEMEN ARAB REPUBLIC
        <option
>YUGOSLAVIA
        <option
>ZAIRE
        <option
>ZAMBIA
        <option
>ZIMBABWE
      </select></td>
</TR>

<TR>
<td align="left" bgcolor=#E8E8E8 class="BodyText">

			Commencement Date(day/month/year)


			 :	</td>
<td width=68% align="left" bgcolor=#E8E8E8 class="BodyText">
    <select name="CommencementDate" class="BodyText" style="color: 000000 ; font-weight: bold"
value="<?=$CommencementDate?>" id="CommencementDate">
      <option> 
        <option
>01
        <option
>02
        <option
>03
        <option
>04
        <option
>05
        <option
>06
        <option
>07
        <option
>08
        <option
>09
        <option
>10
        <option
>11
        <option
>12
        <option
>13
        <option
>14
        <option
>15
        <option
>16
        <option
>17
        <option
>18
        <option
>19
        <option
>20
        <option
>21
        <option
>22
        <option
>23
        <option
>24
        <option
>25
        <option
>26
        <option
>27
        <option
>28
        <option
>29
        <option
>30
        <option
>31
      </select>
/
<select name="CommencementMonth" class="BodyText" style="color: 000000 ; font-weight: bold"
value="<?=$CommencementMonth?>" id="CommencementMonth">
  <option> 
    <option
>01
      <option
>02
        <option
>03
        <option
>04
        <option
>05
        <option
>06
        <option
>07
        <option
>08
        <option
>09
        <option
>10
        <option
>11
        <option
>12
      </select>

/
<select name="CommencementYear" class="BodyText" style="color: 000000 ; font-weight: bold"
value="<?=$CommencementYear?>" id="CommencementYear">
  <option> 
    <option
>1968
      <option
>1969
        <option
>1970
        <option
>1971
        <option
>1972
        <option
>1973
        <option
>1974
        <option
>1975
        <option
>1976
        <option
>1977
        <option
>1978
        <option
>1979
        <option
>1980
        <option
>1981
        <option
>1982
        <option
>1983
        <option
>1984
        <option
>1985
        <option
>1986
        <option
>1987
        <option
>1988
        <option
>1989
        <option
>1990
        <option
>1991
        <option
>1992
        <option
>1993
        <option
>1994
        <option
>1995
        <option
>1996
        <option
>1997
        <option
>1998
        <option
>1999
        <option
>2000
        <option
>2001
        <option
>2002
        <option
>2003
        <option
>2004
        <option
>2005
        <option
>2006
        <option
>2007
        <option
>2008
      </select></td>
</TR>
</TABLE>
  <br />

<div id="div"></div>

  <div align="center">
    <p><br>
      <input name="next" type="submit" class="BodyText" id="Proceed" value="Proceed to Next Section">
      <input name="save" type="submit" class="BodyText"  value="Save Changes">
      <input name="reset" type="reset" class="BodyText" id="reset" value="Clear Form">
      <input name="logout" type="submit" class="BodyText"  value="Logout">
  </div>

</form>

  

</p>
    <p align="center">7/12<br>
    </p>


</BODY>
</HTML>

I use below code to populate a dropdown box with data fed from the mysql database and this works fine

 

 

<?php

$sql="SELECT customer_name, customer_number from tbl_customer ORDER BY customer_name ASC";

$result=mysql_query($sql);

$options="";

while($row=mysql_fetch_array($result)) {

$name=$row['customer_name']." - ".$row['customer_number'];

$options.="<OPTION VALUE=\"$name\">".$name.'</OPTION>';

}

?>

 

 

in html

 

<tr valign="baseline">

      <td nowrap align="right">Customer name:</td>

      <td><SELECT name="customer_name"><br/>

  <?=$options?>

    </SELECT></tr>

Gentlemen this works...but the problem that i have is....

 

This form is just a part of a bigger form....the entire form set has a session id....that is if a user logs in say Mr.Jujubi he will see all the fields that needs to be entered for his records to be stored. he enters it and then as soon as he submits his records the data is sent to the database and at the same time the data that he just entered is displayed in the fields that he just used to key in his details which he can edit and submit again for updation to the database...

 

The problem is all the text boxes work...but not the drop downs..can some please tell me how the code will be for this...

hi there,

im guessing the dropdown ones are submitting to the database but not staying selected,

 

i will assume you are using post for your form and that the handing of it is on the same page,

so try this

<select name="items">
<?php
$sql="SELECT name,number from items";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) 
{
if($_POST['items'] == $row['number'])
{
?>
<option value="<? echo $row['number'];?>" selected="selected"><?echo $row['name'];?></option>
<?php
}
else
{
?>
<option value="<? echo $row['number'];?>"><?echo $row['name'];?></option>
<?php
}

}
?>
</select>

 

cheers

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.