dragoninasia2014 2014-05-25 06:40
浏览 30

从文本字段向表中添加值

In a form there is a text field and a table. If we put a value in that text field the corresponding name needs to be displayed on the table:

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center><table>
<tr><td>no</td><td><input type="text" name="no"  autofocus></td></tr>
</table></center>
<br>
<br>
<center>
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
  <thead>
    <tr>
      <th> Element_Number</th>

    </tr>
  </thead>

<?php
if(isset($_POST['no']))
{
    $c=mysql_connect("localhost","root","");
    mysql_select_db("test");
    if(!$c)
    {
        echo "db prob".mysql_error();
    }

    $no=$_POST['no'];
    $qry=mysql_query("select name from opt where no='$no'");
    if(!$qry)
    {
        echo "ret".mysql_error();
    }


        if(mysql_num_rows($qry)!=0)
        {
            $row=mysql_fetch_array($qry);
            $name=$row['name'];
        }
        else
        {
            echo "query Invalid";
        }
    echo    "<td>" .$name."</td></tr>" ;

}
?>

Using this code the value enters in the table but I want to add the name frequently the value to the table as next row when the next value enter to the text field

  • 写回答

1条回答 默认 最新

  • dongyue110702 2014-05-25 07:01
    关注

    do it with the help of ajax

    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <center>
    <table>
    <tr><td>no</td><td><input type="text" name="no"  autofocus></td></tr>
    <tr><input type="button" name="submit" value="submit"></tr>
    </table></center>
    </form>
    <br>
    <br>
    <center>
    <table id="test_table" cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
      <thead>
        <tr>
          <th> Element_Number</th>
        </tr>
      </thead>
    <tbody>
    </tbody>
    </table>
    
    <script>
    
        $(document).ready(function(){
          $('#submit').click(function(){
            var no=$('[name="no"]');
            $.post('your_current_page_name.php',{"no":no},function(data){
    $("#test_table> tbody").append(data);
    
    });
            });
          });
    </script>
    
    <?php
    if(isset($_POST['no']))
    {
        $c=mysql_connect("localhost","root","");
        mysql_select_db("test");
        if(!$c)
        {
            echo "db prob".mysql_error();
        }
    
        $no=$_POST['no'];
        $qry=mysql_query("select name from opt where no='$no'");
        if(!$qry)
        {
            echo "ret".mysql_error();
        }
    
    
            if(mysql_num_rows($qry)!=0)
            {
                $row=mysql_fetch_array($qry);
                $name=$row['name'];
            }
            else
            {
                echo "query Invalid";
            }
        echo    "<tr><td>" .$name."</td></tr>" ;
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题