1

我正在使用脚本通过 mySQL 中的 php 更新我的记录。除了 $part_no 之外的所有字段都可以更新。

我不明白为什么“part_no”不会更新。

感谢任何帮助。

<?php session_start();


$type=$_POST['type'];
$part_no=$_POST['part_no'];
$description=$_POST['description'];
$artwork=$_POST['artwork'];
$min=$_POST['min'];
$max=$_POST['max'];

$db="naturan8_hero";

$link = mysql_connect("localhost", "XXXXXXX", "XXXXXX");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$query = mysql_query(" UPDATE cartons_current SET type='$type' , part_no='$part_no',     description='$description',artwork='$artwork', min='$min' , max='$max' WHERE part_no='$part_no' ");

if($query) {
header("location: inv_fc_edit_success.php?part_no=" . urlencode($part_no));
}else{
header("location: inv_fc_edit_fail.php");
}

?>

以下是编辑表格:

<?php
$record = $_POST['part_no'];


mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$result=mysql_query(" SELECT * FROM cartons_current WHERE part_no='$record'");
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {

$type=mysql_result($result,$i,"type");
$part_no=mysql_result($result,$i,"part_no");
$description=mysql_result($result,$i,"description");
$artwork=mysql_result($result,$i,"artwork");
$min=mysql_result($result,$i,"min");
$max=mysql_result($result,$i,"max");
?>


<div id="fcICON">Hero</div>
<div id="titleWRAP">
<div id="newTITLE">Edit Part Number</div>
<div id="newINS">This area is designated for editing a part number. Please <b>be careful and alert </b>to your changes, because they are immediately posted.</div>
</div>
<div class="form_hero_new">
<form id="form_editX" method="POST" action="inv_fc_edit2.php"   onfocus="this.value=''">
  <input type="hidden" name="type" type="text" value="FC">
  <input type="hidden" name="part_no" value="<? echo "$record" ?>">
  <div style="width: 500px; height:63px;float:left;">
    <div style="width: 165px; height:65px;float:left;">
      <div id="heroLABEL" style="width:150px">Part Number</div>
      <div id="newPN">
        <textarea name="part_no"  maxlength="20" minlength="6" type="text" style="width: 130px;color:#FFFF00"><? echo "$part_no"?></textarea>
      </div>
4

2 回答 2

5

您正在设置part_no其现有值,这不会进行任何更改:

UPDATE cartons_current SET part_no='$part_no' WHERE part_no='$part_no'
于 2012-05-31T00:03:43.143 回答
0

如果您有一个零件号,PART001并且您在表单中将其更改为PART002,您将PART002用实际数据覆盖任何现有PART001数据。

我会考虑添加一id列并在WHERE子句中使用它。

于 2012-05-31T00:16:23.827 回答