我有一个表单和一个添加按钮,在现有表单下添加相同的表单字段。如果在上面的表格中输入,我想保存数据。 以下是我的代码
<form action="?file=<?= $file ?>" method="post" name="frm_news" enctype="multipart/form-data" class="well">
<h4>
Send Daily Work Report
</h4>
<table id="prjct_tbl">
<tr align="left" valign="middle">
<td height="18" class="text7" ><a id="link" href="?file=daily_report.php&prj_num=<?php if(!isset($_REQUEST['prj_num'])){echo 2;}else {$count = $_REQUEST['prj_num']; echo $count+1;}?>" >Add another Project</a></td>
</tr>
<tr>
<td><hr /></td>
</tr>
<tr align="center" valign="top" >
<td colspan="3" align="center"><? if ($MSG != "") {
echo $MSG;
} ?></td>
</tr>
<tr >
<td width="32%" align="right">Project Name : </td>
<td width="68%"><select name="pid[]" id="pid">
<option value="" selected="selected">Select</option>
<? for ($i = 0; $i < count($data); $i++) { ?>
<option value="<?= $data[$i]['id'] ?>"><?= $data[$i]['pname'] ?></option>
<? } ?>
</select></td>
</tr>
<tr>
<td align="right" valign="top"><span style="color:red">*</span> Deliverable : </td>
<td>
<select name="d_id[]">
<option value="">Select</option>
<?php
$sql = "SELECT tbl_deliverable.*, user_to_deliverable.d_id from tbl_deliverable, user_to_deliverable where tbl_deliverable.id = user_to_deliverable.d_id AND user_to_deliverable.u_id = '".$info['id']."'";
$res = mysql_query($sql);
while ($d_data = mysql_fetch_array($res)) {
?>
<option value ="<?php echo $d_data['id']?>"><?php echo $d_data['name']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top"><span style="color:red">*</span>Time Spent : </td>
<td><select name="hrs[]" class="Field" id="hrs" required style="width: 80px;">
<option value="" selected>Hour</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="min[]" class="Field" id="min" required style="width: 80px;">
<option value="">Minute</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
<option value="41">41</option>
<option value="42">42</option>
<option value="43">43</option>
<option value="44">44</option>
<option value="45">45</option>
<option value="46">46</option>
<option value="47">47</option>
<option value="48">48</option>
<option value="49">49</option>
<option value="50">50</option>
<option value="51">51</option>
<option value="52">52</option>
<option value="53">53</option>
<option value="54">54</option>
<option value="55">55</option>
<option value="56">56</option>
<option value="57">57</option>
<option value="58">58</option>
<option value="59">59</option>
</select></td>
</tr>
<tr>
<td align="right" valign="top">Percentage of deliverable completed : </td>
<td><input name="percent[]" id="percent" type="text">
<input name="employee" type="hidden" id="employee" value="<?= $info['fname'] ?> <?= $info['lname'] ?>">
<input name="email" type="hidden" id="email" value="<?= $info['email'] ?>">
<input name="id" type="hidden" id="id" value="<?= $info['id'] ?>"></td>
</tr>
<tr>
<td align="right" valign="top" nowrap>Comments: </td>
<td><textarea name="comments[]" id="comments"></textarea></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<?php
if(isset($_REQUEST['prj_num'])) {
for($l=1;$l<$_REQUEST['prj_num'];$l++){
?>
<tr >
<td width="32%" align="right">Project Name : </td>
<td width="68%"><select name="pid[]" id="pid">
<option value="" selected="selected">Select</option>
<? for ($i = 0; $i < count($data); $i++) { ?>
<option value="<?= $data[$i]['id'] ?>"><?= $data[$i]['pname'] ?></option>
<? } ?>
</select></td>
</tr>
<tr>
<td align="right" valign="top"><span style="color:red">*</span> Deliverable : </td>
<td>
<select name="d_id[]">
<option value="">Select</option>
<?php
$sql = "SELECT tbl_deliverable.*, user_to_deliverable.d_id from tbl_deliverable, user_to_deliverable where tbl_deliverable.id = user_to_deliverable.d_id AND user_to_deliverable.u_id = '".$info['id']."'";
$res = mysql_query($sql);
while ($d_data = mysql_fetch_array($res)) {
?>
<option value ="<?php echo $d_data['id']?>"><?php echo $d_data['name']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top"><span style="color:red">*</span>Time Spent : </td>
<td><select name="hrs[]" class="Field" id="hrs" required style="width: 80px;">
<option value="" selected>Hour</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="min[]" class="Field" id="min" required style="width: 80px;">
<option value="">Minute</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
<option value="41">41</option>
<option value="42">42</option>
<option value="43">43</option>
<option value="44">44</option>
<option value="45">45</option>
<option value="46">46</option>
<option value="47">47</option>
<option value="48">48</option>
<option value="49">49</option>
<option value="50">50</option>
<option value="51">51</option>
<option value="52">52</option>
<option value="53">53</option>
<option value="54">54</option>
<option value="55">55</option>
<option value="56">56</option>
<option value="57">57</option>
<option value="58">58</option>
<option value="59">59</option>
</select></td>
</tr>
<tr>
<td align="right" valign="top">Percentage of deliverable completed : </td>
<td><input name="percent[]" id="percent" type="text">
<input name="employee" type="hidden" id="employee" value="<?= $info['fname'] ?> <?= $info['lname'] ?>">
<input name="email" type="hidden" id="email" value="<?= $info['email'] ?>">
<input name="id" type="hidden" id="id" value="<?= $info['id'] ?>"></td>
</tr>
<tr>
<td align="right" valign="top" nowrap>Comments: </td>
<td><textarea name="comments[]" id="comments"></textarea></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<?php
}}
?>
<tr bordercolor="#FFFFFF">
<td align="center">
</td>
<td align="left">
<input type="submit" name="Submit" id="Submit" value=" Send " class="btn btn-primary">
<input type="reset" name="Reset" value=" Reset " class="btn"></td>
</tr>
</table>
</form>
这是添加表单元素但在页面刷新时,表单字段为空
答案 0 :(得分:1)
我可以看到字段为空的唯一原因是$ info数组是空的还是未定义的。在刷新页面时(表单提交后),您确定要重新填充该数组吗?你能开启错误报告吗?可能你会在字段中看到一些错误消息。