作者DeepBlueX (空白的)
看板PHP
标题[请益] 请问动态新增失败的原因
时间Sat Jun 15 16:38:55 2013
第一支
<?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
1F:推 bency:新增失败是指怎样的失败?你预期出现什麽而网页却出现什麽? 06/15 17:16
2F:→ bency:2 你的$i一直是1那是因为你echo都是在while里面跑 跟for一点 06/15 17:17
3F:→ bency:关系也没有 再来题外化是建议不要直接拿$_POST去喂query 06/15 17:17
4F:→ DeepBlueX:新增失败是指说 他部会跑我页面的新增 他是会跑出我if e 06/15 18:54
5F:→ DeepBlueX:eles 的新增失败 06/15 20:39
6F:推 PretenderY:我猜是因为按"确认"送出的时候,忘了送work_num的值, 06/16 10:27
7F:→ PretenderY:导致没有$sqlI,所以怎麽跑都是进失败的判断,至於, 06/16 10:28
8F:→ PretenderY:第二个问题应该就跟1F说的一样。 06/16 10:28
9F:推 bency:是说 $_POST['k1_'.$i.''] 这真的有东西吗? 06/16 12:50
10F:→ bency:用var_dump($_POST) 看一下你收到了什麽东西吧 06/16 12:50
11F:→ bency:还有如果以後还会继续碰php&mysql的话 建议开始改用mysqli吧 06/16 12:51
12F:→ bency:或是pdo, mysql_* 这种写法官方已经不建议使用了 06/16 12:51