无法在mySQL中通过php更新部件号字段

时间:2012-05-31 00:00:11

标签: php mysql

我正在使用脚本在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>

2 个答案:

答案 0 :(得分:5)

您正在将part_no设置为其现有值,这将不做任何更改:

UPDATE cartons_current SET part_no='$part_no' WHERE part_no='$part_no'

答案 1 :(得分:0)

如果您有PART001之类的部件号,并且在表单中将其更改为PART002,则您将使用实际的PART002数据覆盖任何现有的PART001数据

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