0

I'm working with XAMPP 1.7.7[PHP: 5.3.8], MYSQL Server version: 5.5.16, Web server Apache/2.2.21, phpMyAdmin Version information: 3.4.5.

I'm trying to generate an application like if user enters the count ("Number_of_Bidders_Participated" according to my application) then display multiple a form (dynamically) for entering multiple client records. And after that fetch all records values using PHP, dynamically create columns in table and insert values in that.

For example: user type count("Number_of_Bidders_Participated") value=3 then display 3 forms For updating client information. I have done that with the help of JavaScript.

I'm using the below code for that:

<!-- 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>   

on picture 1 you can see the output of this process. Here i'm assigning id="biddername'+ i +'" for fetching data to another php file.. But, using the below code i don't getting the proper result.

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

Its showing the error below:

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

please help me for getting the below output. and please help me for dynamically create columns in MySQL server also.

Complete code : Mail file

<!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>

submit.php file

<?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};
    }


    ?>
11
  • This is a notice, not an error. See php.net/manual/en/function.error-reporting.php Commented Feb 21, 2013 at 13:16
  • can you please provide some sample code here.. Commented Feb 21, 2013 at 13:19
  • why are you using biddername.$i instead of biddername[]? Commented Feb 21, 2013 at 13:19
  • i'm helpless to post images here...otherwise..i can show u with images...actually that is only for generating forms or multiple textbox for entering multiple bidder details Commented Feb 21, 2013 at 13:23
  • you cannot post images in comments but you can edit your post to include some. (you could upload your images and provide links if your rep is too low) Commented Feb 21, 2013 at 13:26

2 Answers 2

1

You have to add "name" attribute in your input tag,

<input name="biddername'+ i +'" id="biddername'+ i +'" type="text" value=""/>
Sign up to request clarification or add additional context in comments.

Comments

1

Using dynamic variable names in php isn't usually the best idea, using an array might be a better idea but that wont be the problem with your code.

The following is just a little suggestion, i think your increment_value function is only supposed to run once, but the no_of_bidders_participated can change after you've run it. As this value is passed back to php in the $_POST it should be locked to prevent it being changed before the form is submitted.

<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> 

Could you dump the php $_POST variable so we can see what you'r getting sent back to the server?

var_dump($_POST); or print_r($_POST); should do it.

2 Comments

Dear NickSlash thank you for your support i will try to change your suggestions in my code..actually i'm providing only one time to enter the count there..
DEar NickSlash if i try to add this code application is not working $("no_of_bidders_participated").setAttribute("disabled", true); // stop changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.