douwei1174
2015-12-22 16:26
浏览 101
已采纳

将数据从MySQL数据库加载到下拉列表中的文本框单击

i got this code

<?php

  include("konek.php");

mysql_connect('localhost', 'root', '');
mysql_select_db('psc_db');
$sql = "SELECT * FROM komponen ORDER BY komponen_id";
//$query = "SELECT * FROM taxi_services ORDER BY SID";
$result2 = mysql_query($sql); //$conn

if(isset($_POST["loadbtn"]))
{
    $id = (integer) $_POST["codes"];

    $query = "SELECT nama_komponen, ekuivalen_sks, ekuivalen_jam FROM komponen WHERE komponen_id = '$id' ";
    $result = mysql_query($sql);
    $details = mysql_fetch_array($result);

    $savedName = $details["nama_komponen"];
    $savedJam = $details["ekuivalen_sks"];
    $savedSks = $details["ekuivalen_jam"];
}

?>

<html>
<head>
</head>
<body>

<div id="upserv">
<b id="caption2">Planning</b>
<br/><br/>
    <form name="upServForm" method="post" >
        <?php
        $dropdown = "<select name='codes'>";
        while($row = mysql_fetch_assoc($result2)) 
        {
            $dropdown .= "
<option value='{$row['komponen_id']}'>{$row['komponen_id']}</option>";
        }
        $dropdown .= "
</select>";
    ?>
     Service ID  <?php echo $dropdown; ?> <input type="submit" value="Load" name="loadbtn">
        <table width="300" border="0">
          <tr>
            <td>Name</td>
            <td><input type="text" name="upName" style="text-align:right" value="<? echo $savedName; ?>" /></td>
          </tr>
          <tr>
            <td>ekuivalen sks</td>
            <td><input type="text" name="upCost" style="text-align:right" value="<? echo $savedJam; ?>" /></td>
          </tr>
          <tr>
            <td>ekuivalen jam</td>
            <td><input type="text" name="upActive" style="text-align:right" value="<? echo $savedSks; ?>" /></td>
          </tr>
        </table>
</div>
<br/>
<div id="buttons">
    <input type="reset" value="Clear" /> <input type="submit" value="Save" name="updatebtn" />
</div>
    </form>

</body>
</html>

and the result is something like this

result

I still haven't sucessfully display the data when I click the button. I got the example code from another post, and I tried it and above is the result(but I'm still fail). All I want to do is to display the data into the textbox without the load button

Can you help me coding this code please, thank you

</div>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongyupan4850 2015-12-22 16:33
    最佳回答

    I think short tags is not configured in your server. you have to replace <? with <?php

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题