PHP / HTML使用组合框

时间:2016-01-16 23:20:09

标签: php html

我有一个从数据库加载值的组合框。我想当用户从组合框中选择值时,表单应该将相应的值从数据库加载到html表单中。这是我正在尝试的代码:

<!DOCTYPE html>
<html>
<head>
<title>Obracun plata</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="layout.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<?php
error_reporting(0);
mysql_connect("localhost", "root", "");
mysql_select_db("zaposleni");
    $query = "SELECT * FROM radnici;";
$rezultat = mysql_query($query);
?>

<div id="wrapper">
  <div id="logo">
<h1>Obračun plata</h1>
<p>Income calculator</p>
  </div>
  <div id="menu">
<ul>
<li><a href="index.html">Pocetna</a></li>
  <li><a href="podaci_o_radnicima.php" class="active">Podaci o radnicima</a>                       </li>
  <li><a href="spisak_radnih_mjesta.php">Spisak radnih mjesta</a></li>
  <li><a href="obracun.php">Obracun</a></li>
  <li><a href="spisak_gradova.php">Spisak gradova</a></li>
  <li><a href="spisak_mjeseci.php">Spisak mjeseci</a></li>
    </ul>
  </div>
  <div id="page">
  <div id="content">

<br/>
  <td>Radnici:</td>
<td>
<select name="Radnik">
<?php
error_reporting(0);
mysql_connect("localhost", "root", "");
mysql_select_db("zaposleni");
    $query = "SELECT * FROM radnici;";
$rezultat = mysql_query($query);
for($data = mysql_fetch_row($rezultat); $data != null; $data =         mysql_fetch_row($rezultat))
    echo "<option value='" . $data[0] . "'>" . $data[1] . " " . $data[2];
?>
</select>


<p>&nbsp;</p>


<?php
error_reporting(0);

if($_POST["Radnik"] == "")
        echo "<div style='color:red'>Niste izabrali radnika</div>";
    else
    {
mysql_connect("localhost", "root", "");
mysql_select_db("zaposleni");
    $query1 = "SELECT * FROM radnici WHERE id ='" . $_POST["Radnik"] . "';";
    $query2 = "SELECT grad.naziv FROM grad, radnici WHERE radnici.grad_id=grad.id AND radnici.id='" . $_POST["Radnik"] . "';";
    $query3 = "SELECT radno_mjesto.naziv FROM radno_mjesto, radnici WHERE radnici.radno_mjesto_id=radno_mjesto.id AND radnici.id='" . $_POST["Radnik"] . "';";
$rezultat1 = mysql_query($query1);
$rezultat2 = mysql_query($query2);
$rezultat3 = mysql_query($query3);

$data1 = mysql_fetch_row($rezultat1);
$data2 = mysql_fetch_row($rezultat2);
$data3 = mysql_fetch_row($rezultat3);

$prezime = $data1[1];
$ime = $data1[2];
$brtelefona = $data1[3];
$mail = $data1[4];
$brtekuceg = $data1[5];
$strucnasprema = $data1[6];
$godradnogstaza = $data1[7];
$adresa = $data1[8];
$grad = $data2[0];
$radnomjesto = $data3[0];
    }
?>


<form action="podaci_o_radnicima.php" method="post">
<table>
<tr>
<td>Prezime:</td>
<td><input name="prezime" type="text"  size="45" maxlength="45" value="<?php         echo $prezime?>"  readonly="readonly" /></td>
</tr>
<tr>
<td>Ime:</td>
<td><input type="text" name="ime" maxlength="45" size="45" value="<?php echo     $ime ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Broj telefona:</td>
<td><input type="text" name="broj_telefona" maxlength="45" size="45" value="    <?php echo $brtelefona ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" maxlength="45" size="45" value="<?php     echo $mail ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Broj tekuceg:</td>
<td><input type="text" name="broj_tekuceg" maxlength="45" size="45" value="<?php echo $brtekuceg ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Strucna sprema:</td>    
<td><input type="text" name="strucna sprema" maxlength="45" size="45" value="<?php echo $strucnasprema ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Godina radnog staza:</td>
<td><input type="text" name="god_radnog_staza" maxlength="45" size="45" value="<?php echo $godradnogstaza ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Adresa:</td>
<td><input type="text" name="adresa" maxlength="45" size="45" value="<?php     echo $adresa ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Grad:</td>
<td><input type="text" name="grad" maxlength="45" size="45" value="<?php echo $grad ?>" readonly="readonly"/></td>
</tr>
<tr>
<td>Radno mjesto:</td>
<td><input type="text" name="radno_mjesto" maxlength="45" size="45" value="<?php echo $radnomjesto ?>" readonly="readonly"/></td>
</tr>
</table>
<table>
<tr><td></td><td colspan="4" align="center"><input type="submit" value="Prikazi"> </td></tr>
</table>
</form>
  </div>
</body>
</html>

0 个答案:

没有答案