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

将数据从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条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型