dsjklb0205 2014-12-17 19:59
浏览 6
已采纳

too long

I have two column name varchar and area text

name    area
abc     12a
dfg     test

Now I want to update each of them from my page where I input some text to the textarea fetched from tow rows.

<?
if(isset($_POST['submit'])) {

    $i = 0;
    foreach($_POST['txt'] as $textarea) {
        @$val[$i] = $val[$i].$textarea;
        $i++;
    }

    foreach($val as $value){
    $q= mysql_query("UPDATE table_name SET name = '$value' WHERE `area` = '??'");
    echo "Success"; }

    $sql="select * from table_name";
    $res=mysql_query($sql);
    ?>

    <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <table border="1">

                    <thead>
                      <tr>
                        <th>NAME</th>
                        <th>AREA</th>                        
                    </tr>
    <?php while($row=mysql_fetch_assoc($res)) 
    {
    ?>                            
            <tr>
            <td><?php echo $row['name']; ?></td>     
            <td><textarea rows="4" cols="40"  name="txt[]"><?php  echo $row['area']; ?>    </textarea><br/>            
            </td>             
             </tr>
            <tr>                        
                    </tr>
                <?php } ?>             

     <tr>
     <td><input type="submit" name="submit" id="submit" value="Update" /></td>
     </tr>
     </table>                
     </form>  

I am getting the name but could not update/insert it in area for that name. How do I accomplish this?

  • 写回答

2条回答 默认 最新

  • doujuegai8830 2014-12-18 09:20
    关注

    the most easy fix is to take a hidden input field and pass the $row['name']

    <input type="hidden" name="name[]" value="<?php echo $row['name'];?>"/>
    

    then

    if(isset($_POST['submit'])) {
    $area=$_POST['txt'];
    $name=$_POST['name'];
    $count=count($area);
    
    for($i=0; $i<$count; $i++)
        {
    
        if(mysql_query("UPDATE table_name SET area = '".$area[$i]."' WHERE `name` = '".$name[$i]."'")) 
    {
    

    NB:-if u have a id column then take hidden input field with $row['id'] and do the same

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)