0

我正在使用 XAMPP 1.7.7[PHP: 5.3.8],MYSQL Server 版本:5.5.16,Web 服务器 Apache/2.2.21,phpMyAdmin 版本信息:3.4.5。

我正在尝试生成一个应用程序,例如用户输入计数(根据我的应用程序为“Number_of_Bidders_Participated”)然后显示多个表单(动态)以输入多个客户记录。然后使用 PHP 获取所有记录值,在表中动态创建列并在其中插入值。

例如:用户类型 count("Number_of_Bidders_Participated") value=3 然后显示 3 个表单用于更新客户信息。我在 JavaScript 的帮助下做到了这一点。

我为此使用以下代码:

<!-- Basic code-->
        Number of Bidders Participated:     
            <input name="no_of_bidders_participated" id="no_of_bidders_participated" type="text" style="vertical-align: middle;" /> 
            <input type="button" onclick="increment_value()" value="Add Bidders info" />
            <div id="container">
            </div>                      
<script type="text/javascript">
        var counter = 0;
        function increment_value(chk) 
        {       
            var get = $("#no_of_bidders_participated").val();           
            if (counter > 0)
            {
              return;
            }
            else
            {
                counter++;                  
                for(i=1; i<=get; i++)
                {               
                       $('#container').append('<br>Bidder '+ i +' Name: <input id="biddername'+ i +'" type="text" value=""/> Bidder'+ i +' Address: <input id="bidderadd'+ i +'" type="text" value=""/> Bidder'+ i +' Phone Number: <input id="bidderphone '+ i +'" type="text" value=""/><br><br> Bidder'+ i +' Email ID: <input id="bidderemail'+ i +'" type="text" value=""/> Bidder'+ i +' Cotted Amount: <input id="biddercotted_amount'+ i +'" type="text" value=""/> Bidder'+ i +' Tender Awarded: <select id="biddertender_awarded'+ i +'"><option value="No">No</option><option value="Yes">Yes</option></select><br><br><br>');
                }                                           

            }
        }   
</script>   

在图 1 中,您可以看到此过程的输出。在这里,我正在分配将id="biddername'+ i +'"数据提取到另一个 php 文件。但是,使用下面的代码我没有得到正确的结果。

${"biddername" . $i} = $_POST['biddername'.$i];

它显示以下错误:

Notice: Undefined index: biddername1 in C:\xampp\htdocs\tender_monitoring_system\add_participated_bidders_info_submit.php on line 15

请帮助我获得以下输出。并请帮助我在 MySQL 服务器中动态创建列。

完整代码:邮件文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>.::Tender Monitoring System::.</title>
        <link rel="stylesheet" href="application.css" type="text/css" />

        <script type="text/javascript" src="date/jquery-latest.js"></script>
        <script type="text/javascript">
        var counter = 0;
        function increment_value(chk) 
        {       
                var get = $("#no_of_bidders_participated").val();   

                if (counter > 0)
                {
                  return;
                }
                else
                {
                    counter++;                  
                    for(i=1; i<=get; i++)
                    {               
                           $('#container').append('<br>Bidder '+ i +' Name: <input id="biddername'+ i +'" type="text" value=""/> Bidder'+ i +' Address: <input id="bidderadd'+ i +'" type="text" value=""/> Bidder'+ i +' Phone Number: <input id="bidderphone '+ i +'" type="text" value=""/><br><br> Bidder'+ i +' Email ID: <input id="bidderemail'+ i +'" type="text" value=""/> Bidder'+ i +' Cotted Amount: <input id="biddercotted_amount'+ i +'" type="text" value=""/> Bidder'+ i +' Tender Awarded: <select id="biddertender_awarded'+ i +'"><option value="No">No</option><option value="Yes">Yes</option></select><br><br><br>');
                    }                                           

                }
        }   

        </script>       
    </head>
    <body>
        <a href="http://localhost/tender_monitoring_system/"><img align="right" width="100px" height="40px" src="home.gif" alt="Home" /></a>
        <a href="http://localhost/tender_monitoring_system/add_participated_bidders_information.php"><img align="right" width="100px" height="40px" src="back.gif" alt="Back" /></a>    
        <div id="heading"><br><h1>Tender Monitoring System</h1><h3>Tender Status</h3><br>  
        </div>
        <?php
         $txtSearch = $_POST['txtSearch'];
         require('db_connect.php'); 
        // The form has been submitted, query results
            if ($txtSearch!='none')
            {
                ?>
                <center><br><br>
                <form id="search_form" name="search_form" action="submit.php" method="post">
                    <?php           
                    $queryitem = "SELECT tender_status,tender_number FROM tender WHERE tender_number='$txtSearch'";
                    // Execute the query 
                    $result = mysql_query($queryitem);  
                    ?><b>
                    Tender Number :     
                    <select name="qtender_number" id="qtender_number" disabled="disabled">
                        <?php   
                        while($row = mysql_fetch_array($result))
                        {   
                        $getvalue_number=$row["tender_number"]; //$getvalue_status has old tender_number value ramesh
                        ?>
                            <option value="<?php echo $row['tender_number'] ?>"><?php echo $row['tender_number'] ?></option>
                        <?php
                        }
                        ?>        
                    </select>   
                    <input type="hidden" name="getvalue_number" value="<?php echo $getvalue_number ?>"> <?php //for passing variable value to another file?>
                    <?php           
                    $queryitem = "SELECT tender_status FROM tender WHERE tender_number='$txtSearch'";
                    // Execute the query 
                    $result = mysql_query($queryitem);  
                    ?><b>                   
                    Tender Call:
                  <select name="call" id="call">
                   <option selected="selected" label="none" value="none">- - Select Tender Call - -</option>
                      <option value="1st Call">1st Call</option>
                      <option value="2nd Call">2nd Call</option>
                      <option value="3rd Call">3rd Call</option>
                      <option value="4th Call">4th Call</option>
                      <option value="5th Call">5th Call</option>
                      <option value="6th Call">6th Call</option>
                      <option value="7th Call">7th Call</option>
                      <option value="8th Call">8th Call</option>
                      <option value="9th Call">9th Call</option>
                      <option value="10th Call">10th Call</option>
                  </select><b><br><br>                
                  Tender Status:  
                  <select name="tender_status" id="tender_status">
                   <option selected="selected" label="none" value="none">- - Select Tender Status - -</option>
                      <option value="AA Received">AA Received</option>
                      <option value="NIT Awaited">NIT Awaited</option>
                      <option value="NIT Received">NIT Received</option>
                      <option value="Online Tender">Online Tender</option>
                      <option value="Locked Tender">Locked Tender</option>
                      <option value="Opened Tender">Opened Tender</option>
                      <option value="Online Technical Opened">Online Technical Opened</option>
                      <option value="Online Financial Opened">Online Financial Opened</option>
                      <option value="Sanctioned For Award">Sanctioned For Award</option>
                      <option value="Rejected Tender">Rejected Tender</option>
                      <option value="Recalled Tender">Recalled Tender</option>
                  </select>               
                    Number of Bidders Participated:     
                        <input name="no_of_bidders_participated" id="no_of_bidders_participated" type="text" style="vertical-align: middle;" /> 
                        <input type="button" onclick="increment_value()" value="Add Bidders info" />
                        <div id="container">
                        </div>

                    <br><br>        
                    <input id="submit" type="submit" value="Submit" />
                </form> 
                    <?php               
            }           
        ?>          
    </body>
</html>

提交.php 文件

<?php
    //$qtender_number = $_POST['qtender_number'];

    $getvalue_number = $_POST['getvalue_number'];
    $tender_call = $_POST['call'];
    $getvalue_status = $_POST['tender_status']; 
    $no_of_bidders = $_POST['no_of_bidders_participated'];

    echo $getvalue_number; //working
    echo $tender_call;
    echo $getvalue_status;
    echo $no_of_bidders;
    for($i=1; $i<=$no_of_bidders; $i++)
    {
        ${"biddername" . $i} = $_POST['biddername'.$i]; //problem here..
        echo ${"biddername" . $i};
    }


    ?>
4

2 回答 2

1

在 php 中使用动态变量名通常不是最好的主意,使用数组可能是一个更好的主意,但这不会是您的代码的问题。

以下只是一个小建议,我认为您的increment_value函数应该只运行一次,但运行no_of_bidders_participated后可以更改。由于这个值被传回 php 中,$_POST它应该被锁定以防止它在提交表单之前被更改。

<script type="text/javascript">
var counter = 0;
function increment_value(chk) 
{       
  var bidder_count = $("#no_of_bidders_participated").val();           
  if (counter > 0) {
    return;
  } else {
    counter++;
    $("#no_of_bidders_participated").setAttribute("disabled", true); // stop changes
    for(i=1; i<=bidder_count; i++) {               
      $('#container').append('<br>Bidder '+ i +' Name: <input id="biddername'+ i +'" type="text" value=""/> Bidder'+ i +' Address: <input id="bidderadd'+ i +'" type="text" value=""/> Bidder'+ i +' Phone Number: <input id="bidderphone '+ i +'" type="text" value=""/><br><br> Bidder'+ i +' Email ID: <input id="bidderemail'+ i +'" type="text" value=""/> Bidder'+ i +' Cotted Amount: <input id="biddercotted_amount'+ i +'" type="text" value=""/> Bidder'+ i +' Tender Awarded: <select id="biddertender_awarded'+ i +'"><option value="No">No</option><option value="Yes">Yes</option></select><br><br><br>');
    }
  }
}   
</script> 

您能否转储 php $_POST 变量,以便我们可以看到您发送回服务器的内容?

var_dump($_POST);或者print_r($_POST);应该这样做。

于 2013-02-21T14:11:25.487 回答
1

您必须在输入标签中添加“名称”属性,

<input name="biddername'+ i +'" id="biddername'+ i +'" type="text" value=""/>
于 2013-02-21T14:14:35.287 回答