[請益] 請問動態新增失敗的原因
第一支
<?php session_start(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upower</title>
請輸入要查詢的說明書
<br>
<br>
<form name="form" method="post" action="WorkContent_Insert.php">
<input type="text" name="work_num" /> <br>
<br>
<input type="submit" name="Submit" value="查詢">
</form>
第二支
<?php require_once('../Link/UPower.php'); ?>
<?php
include("../Link/UPower.php");
$work_num = $_POST['work_num'];
if($_POST['yes']=="確認")
{
if(isset($_POST['work_num']))
{
for ($i=1;$i<=$count;$i++)
{
mysql_select_db($database, $link);
$sqlIns = sprintf("INSERT INTO b_work_content (work_num, work_content, k1, k2, s1, s2, a1, a2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
$_POST['work_num'],'"'.$_POST['work_content_'.$i.''].'"','"'.$_POST['k1_'.$i.''].'"','"'.$_POST['k2_'.$i.''].'"','"'.$_POST['s1'.$i.''].'"','"'.$_POST['s2'.$i.''].'"','"'.$_POST['a1'.$i.''].'"','"'.$_POST['a2'.$i.''].'"');
$sqlI = mysql_query($sqlIns, $link) or die(mysql_error());
}
}
if($sqlI)
{
echo '新增成功';
echo '<meta http-equiv=REFRESH CONTENT=0;url=WorkContent_search.php>';
}
else
{
echo '新增失敗!';
echo '<meta http-equiv=REFRESH CONTENT=0;url=WorkContent_search.php?department_name=$department_name&position_name=$position_name&work_num=$work_num>';
}
}
mysql_select_db($database, $link);
$sql_1 = "SELECT * FROM b_work_description where work_num = $work_num ";
$result_1 = mysql_query($sql_1);
$result = mysql_query($sql_1,$link);
$count = mysql_num_rows($result);
echo $count;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>工作內容 - 新增</title>
</head>
<body>
<form method="post" action="WorkContent_Insert.php">
<input type="hidden" name="count" id="count" value="<?php echo $count; ?>"/>
<table border="1">
<tr>
<td> 工作任務(執掌)</td>
<td>知識(K)</td>
<td >技能(s)</td>
<td>工作動力/行為(A)</td></tr>
<?
for($i=1;$i<=$count;$i++){
while($row_1 = mysql_fetch_row($result_1))
{
?>
<tr>
<td rowspan=2>
<? echo $row_1[5];?>
<input type="hidden" name="work_content_[<?echo $i ;?>]" id="work_content" value="<?php echo $row_1[5]; ?>"/>
</td>
<td><select name="k1_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="k1_input_[<?echo $i ;?>]" id="k1_input"/></td>
<td><select name="k2_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="k2_input_[<?echo $i ;?>]" id="k2_input"/></td>
<td><select name="s1_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="s1_input_[<?php echo $i; ?>]" id="s1_input"/></td></tr>
<tr>
<td><select name="s2_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="s2_input_[<?php echo $i; ?>]" id="s2_input"/></td>
<td><select name="a1_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="a1_input_[<?echo $i ;?>]" id="a1_input"/></td>
<td><select name="a2_[<?echo $i ;?>]" >
<?php
$sql_2 = "select * from b_function_definition";
$result_2 = mysql_query($sql_2,$link);
while ($row_2 = mysql_fetch_row($result_2)):
?>
<option value="<?php echo $row_2[2]?>"><?php echo $row_2[2]?></option>
<?php endwhile?>
<?
$sql_3 = "select * from b_work_content_input";
$result_3 = mysql_query($sql_3,$link);
While ($row_3 = mysql_fetch_row($result_3)):
?>
<option value="<?php echo $row_3[1]?>"><?php echo $row_3[1]?></option>
<?php endwhile?>
</select>
<input type="text" name="a2_input_[<?echo $i ;?>]" id="a2_input"/></td>
</tr>
<?
}
}
?>
</table>
<input type="submit" name="yes" id="yes" value="確認" />
<input type="reset" name="reset" id="reset" value="取消" /><br>
<a href="Work_Insert.php?department_name=<?php echo $department_name; ?>&position_name=<?php echo $position_name; ?>&work_num=<?php echo $work_num; ?>">回上一頁</a>
<a href="../Business.php">回首頁</a>
<br>
</form>
</body>
</html>
第一個問題:
請問為什麼新增一直失敗?
第二個問題:
我查看過我的for迴圈 他的i直都是在1
不管我資料庫有幾筆資料 是因我放錯地方嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.44.19
推
06/15 17:16, , 1F
06/15 17:16, 1F
→
06/15 17:17, , 2F
06/15 17:17, 2F
→
06/15 17:17, , 3F
06/15 17:17, 3F
→
06/15 18:54, , 4F
06/15 18:54, 4F
→
06/15 20:39, , 5F
06/15 20:39, 5F
推
06/16 10:27, , 6F
06/16 10:27, 6F
→
06/16 10:28, , 7F
06/16 10:28, 7F
→
06/16 10:28, , 8F
06/16 10:28, 8F
推
06/16 12:50, , 9F
06/16 12:50, 9F
→
06/16 12:50, , 10F
06/16 12:50, 10F
→
06/16 12:51, , 11F
06/16 12:51, 11F
→
06/16 12:51, , 12F
06/16 12:51, 12F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
4
20
6
17