drpkcwwav20524605 2012-06-24 12:28
浏览 9
已采纳

too long

Only editor can post into database but the price could'nt Post into database..

So, how can i make query let say 1st Row in form has Field 1 = Fullname, Field 2 = Age.. and i can add new row again with the same field and submit all information to array into database

<?php
    session_start();
    include "_config/config.php";
    //include "header.php";


    if (isset($_POST["editor"])) //&& ($_POST["price"]) && is_array($_POST["price"]) && count($_POST["price"]) > 0) 
    { 
    foreach($_POST["editor"] as $editor)
       { 
           // echo htmlspecialchars($editor, ENT_QUOTES); 
           mysql_connect($server, $db_user, $db_pass)  or die ("Database CONNECT Error (line 62)"); 
           mysql_db_query($database, "INSERT INTO arrayins VALUES   ('','$editor','$price')");

       echo "Data Successfully Added";
            echo '<br />'; 
        } 
    }
    ?>
  • 写回答

1条回答 默认 最新

  • dpl74687 2012-06-24 12:47
    关注

    You can first determine the number of rows posted, and then loop over the row index and get the appropriate values:

    $num_rows = is_array($_POST["editor"]) ? count($_POST["editor"]) : 0;
    
    for ($i = 0; $i < $num_rows; $i++) {
        $editor = $_POST["editor"][$i];
        $price = $_POST["price"][$i];
    
        // your SQL code here using $editor and $price
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址