从MYSQL查询填充文本框

时间:2012-10-03 10:44:33

标签: php mysql

我需要查询数据库,然后用结果填充文本框输入。

我正在尝试

日期:

   <td>
      <?php 
         $selectedSPK=$_POST['SPKSelect'];
        $assigned = $_POST['Sales_Exec'];
        $date = $_POST['DateSelect'];

if ($selectedSPK)

{
    $Call1query = "SELECT  Call1 FROM Data WHERE SPKCustNo  = '$selectedSPK' ";

$Call1result = mysql_query($Call1query);


 while( $row = mysql_fetch_array($Call1result) ){
    $Call1 = $row["$Call1Result"];

    }

}
?>
    <input type="text" name="Call1" id="Call1" value="<?php echo( htmlspecialchars( $Call1) ); ?>"/></td>

但是什么都没有,我哪里出错了,文字输入似乎很难填充!

三江源!

4 个答案:

答案 0 :(得分:2)

改为使用

$Call1 = $row["Call1"];

答案 1 :(得分:1)

替换

$Call1 = $row["$Call1"];

$Call1 = $row["Call1"];

答案 2 :(得分:0)

问题在于改变

$Call1 = $row["$Call1Result"];

$Call1 = $row['Call1'];   //here column name comes not variable name

答案 3 :(得分:0)

试试这个

<td>
  <?php 
     $selectedSPK=$_POST['SPKSelect'];
    $assigned = $_POST['Sales_Exec'];
    $date = $_POST['DateSelect'];

if ($selectedSPK)

{
 $Call1query = "SELECT  Call1 FROM Data WHERE SPKCustNo  = '$selectedSPK' ";

$Call1result = mysql_query($Call1query);


 while( $row = mysql_fetch_array($Call1result) ){
$Call1 = $row["Call1"];

}

}?>

<input type="text" name="Call1" id="Call1" value="<?php echo( htmlspecialchars( $Call1) ); ?>"/></td>