我正在使用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获取所有记录值,在表中动态创建列并在其中插入值。
例如:用户类型计数(“Number_of_Bidders_Participated”)值= 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>
submit.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};
}
?>
答案 0 :(得分:1)
在php中使用动态变量名称通常不是最好的主意,使用数组可能是一个更好的主意,但这不会是你的代码的问题。
以下只是一个小小的建议,我认为你的increment_value
函数只能运行一次,但no_of_bidders_participated
可能会在运行后发生变化。当这个值传递回$_POST
中的php时,它应该被锁定以防止在提交表单之前更改它。
<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);
应该这样做。
答案 1 :(得分:1)
您必须在输入标记中添加“name”属性
<input name="biddername'+ i +'" id="biddername'+ i +'" type="text" value=""/>