我正在尝试更新表单中未填写的某些字段,但是当我单击更新按钮时,先前存储的值被设置为0并且新插入的值保持不变。如果我再次尝试编辑记录,则此操作继续进行。以前存储的值将设置为0。如果有人可以看一下并帮帮我,那太好了

这是编辑页面的代码。

    <?php
    include 'db.php';
    $mykey1=$_REQUEST['key1'];
    $mykey2=$_REQUEST['key2'];
    $mykey3=$_REQUEST['key3'];
    $mykey4=$_REQUEST['key4'];
    $mykey5=$_REQUEST['key5'];
    $mykey6=$_REQUEST['key6'];
    $mykey7=$_REQUEST['key7'];
    $mykey8=$_REQUEST['key8'];
    $mykey9=$_REQUEST['key9'];
    $mykey10=$_REQUEST['key10'];
    $mykey11=$_REQUEST['key11'];
    $mykey12=$_REQUEST['key12'];
    $mykey13=$_REQUEST['key13'];
    $mykey14=$_REQUEST['key14'];
    $mykey15=$_REQUEST['key15'];
    $mykey16=$_REQUEST["key16"];



    $t6 = "SELECT t.name FROM sicherheitsunterweisung as t where t.id = '".$mykey6."'";
    $r6 = mysql_query($t6)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r6)){
    $x6= $row['name'];  //handle rows.
    }


    $t7 = "SELECT t.training FROM trainings as t where t.id = '".$mykey7."'";
    $r7 = mysql_query($t7)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r7)){
    $x7= $row['training'];  //handle rows.
    }

    $t8 = "SELECT t.training FROM trainings as t where t.id = '".$mykey8."'";
    $r8 = mysql_query($t8)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r8)){
    $x8= $row['training'];  //handle rows.
    }

    $t9 = "SELECT t.training FROM trainings as t where t.id = '".$mykey9."'";
    $r9 = mysql_query($t9)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r9)){
    $x9= $row['training'];  //handle rows.
    }

    $t10 = "SELECT t.training FROM trainings as t where t.id = '".$mykey10."'";
    $r10 = mysql_query($t10)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r10)){
    $x10= $row['training'];  //handle rows.
    }

    $t11 = "SELECT t.training FROM trainings as t where t.id = '".$mykey11."'";
    $r11 = mysql_query($t11)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r11)){
    $x11= $row['training'];  //handle rows.
    }

    $t12 = "SELECT t.training FROM trainings as t where t.id = '".$mykey12."'";
    $r12 = mysql_query($t12)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r12)){
    $x12= $row['training'];  //handle rows.
    }

    $t13 = "SELECT t.training FROM trainings as t where t.id = '".$mykey13."'";
    $r13 = mysql_query($t13)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r13)){
    $x13= $row['training'];  //handle rows.
    }

    $t14 = "SELECT t.training FROM trainings as t where t.id = '".$mykey14."'";
    $r14 = mysql_query($t14)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r14)){
    $x14= $row['training'];  //handle rows.
    }

    $t15 = "SELECT t.training FROM trainings as t where t.id = '".$mykey15."'";
    $r15 = mysql_query($t15)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r15)){
    $x15= $row['training'];  //handle rows.
    }

    $t16 = "SELECT t.training FROM trainings as t where t.id = '".$mykey16."'";
    $r16 = mysql_query($t16)or die($myQuery."<br/><br/>".mysql_error());
    while($row = mysql_fetch_assoc($r16)){
    $x16= $row['training'];  //handle rows.
    }
    echo "<form action='update.php?key1=" . $mykey1 .  "'method='POST'>";
    echo "<center><table>";
    echo  "<TR><TD>ID Number</TD><TD><INPUT TYPE=text name='pers_nr' value=$mykey1 disabled = true></TD></TR>";
    echo  "<TR><TD>Family Name</TD><TD><INPUT TYPE=text name='n_name' value=$mykey2 disabled = true ></TD></TR>";
    echo  "<TR><TD>First Name</TD><TD><INPUT TYPE=text name='v_name' value=$mykey3 disabled = true></TD></TR>";
    echo  "<TR><TD>Access Level</TD><TD><INPUT TYPE=text name='berectigung_id' value=$mykey4 disabled = true></TD></TR>";
    echo  "<TR><TD>Sicherheitsunterweisung</TD><TD><INPUT TYPE=text name='sicherheisunterweisung_id' value=$x6 disabled = true ></TD></TR>";
    echo  "<TR><TD>Experience</TD><TD><INPUT TYPE=text name='erfahrungen_id' value=$mykey5 ></TD></TR>";
    if($x7!= NULL)
    {
    echo  "<TR><TD>Schulung 1</TD><TD><INPUT TYPE=text name='schulungen_id1' value=$x7 disabled = true></TD></TR>";
     }
     else {
    $sql1="SELECT id,training  FROM trainings as s";
    $result=mysql_query($sql1);
    echo "<TR><TD> Schulung 1</TD><TD> <select name='schulungen_id1'><option value            default>$x7</option>";
    while ($row = mysql_fetch_array($result))
    {
    echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
    }
    echo "</select></TD></TR>";
    }
    if($x8!= NULL)
    {
    echo  "<TR><TD>Schulung 2</TD><TD><INPUT TYPE=text name='schulungen_id2' value=$x8 disabled = true></TD></TR>";
    }
    else {
    $sql2="SELECT id,training  FROM trainings as s";
    $result=mysql_query($sql2);
    echo "<TR><TD> Schulung 2</TD><TD> <select name='schulungen_id2'><option value default>$x8</option>";
    while ($row = mysql_fetch_array($result))
    {
    echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
     }
     echo "</select></TD></TR>";
    }
   if($x9!= NULL)
   {
   echo  "<TR><TD>Schulung 3</TD><TD><INPUT TYPE=text name='schulungen_id3' value=$x9 disabled = true></TD></TR>";
    }
   else {
   $sql3="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql1);
   echo "<TR><TD> Schulung 3 </TD><TD><select name='schulungen_id3'><option value default>$x9</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
   }
   echo "</select></TD></TR>";
   }
   if($x10!= NULL)
   {
   echo  "<TR><TD>Schulung 4</TD><TD><INPUT TYPE=text name='schulungen_id4' value=$x10 disabled = true></TD></TR>";
   }
   else {
   $sql4="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql4);
   echo "<TR><TD> Schulung 4 </TD><TD><select name='schulungen_id4'><option value default>$x10</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
   }
   echo "</select></TD></TR>";
   }
   if($x11 != NULL)
   {
   echo  "<TR><TD>Schulung 5</TD><TD><INPUT TYPE=text name='schulungen_id5' value=$x11  disabled = true></TD></TR>";
   }
   else {
   $sql5="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql5);
   echo "<TR><TD> Schulung 5 </TD><TD><select name='schulungen_id5'><option value       default>$x11</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
   }
   echo "</select></TD></TR>";
   }
   if($x12 != NULL)
   {
   echo  "<TR><TD>Schulung 6</TD><TD><INPUT TYPE=text name='schulungen_id6' value=$x12 disabled = true></TD></TR>";
   }
   else
   {
   $sql6="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql6);
   echo "<TR><TD> Schulung 6 </TD><TD><select name='schulungen_id6'><option value default>$x12</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
   }
   echo "</select></TD></TR>";
   }
   if($x13!= NULL)
   {
   echo  "<TR><TD>Schulung 7</TD><TD><INPUT TYPE=text name='schulungen_id7' value=$x13 disabled = true></TD></TR>";
   }
   else {
   $sql7="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql7);
   echo "<TR><TD> Schulung 7</TD><TD> <select name='schulungen_id7'><option value default>$x13</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
   }
   echo "</select></TD></TR>";
   }
   if($x14!= NULL)
   {
   echo  "<TR><TD>Schulung 8</TD><TD><INPUT TYPE=text name='schulungen_id8' value=$x14 disabled = true></TD></TR>";
   }
   else {
   $sql8="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql8);
   echo "<TR><TD> Schulung 8</TD><TD> <select name='schulungen_id8'><option value default>$x14</option>";
   while ($row = mysql_fetch_array($result))
   {
   echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
    }
   echo "</select></TD></TR>";
    }
   if($x15!= NULL)
   {
    echo  "<TR><TD>Schulung 9</TD><TD><INPUT TYPE=text name='schulungen_id9' value=$x15 ></TD></TR>";
    }
   else {
   $sql9="SELECT id,training  FROM trainings as s";
   $result=mysql_query($sql9);
   echo "<TR><TD> Schulung 9 </TD><TD><select name='schulungen_id9'><option value default>$x15</option>";
   while ($row = mysql_fetch_array($result))
    {
    echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
     }
    echo "</select></TD></TR>";
    }
    if($x16!= NULL)
    {
    echo  "<TR><TD>Schulung 10</TD><TD><INPUT TYPE=text name='schulungen_id10' value=$x16 ></TD></TR>";
    }
    else {
    $sql10="SELECT id,training  FROM trainings as s";
    $result=mysql_query($sql10);
    echo "<TR><TD> Schulung 10</TD><TD> <select name='schulungen_id10'><option value default>$x16</option>";
    while ($row = mysql_fetch_array($result))
    {
    echo "<option value='".$row['id']."'>" . $row['training'] . "</option>";
    }
    echo "</select></TD></TR>";
    }
    echo "<TR><TD><INPUT TYPE=submit value=Update></TD><TD><INPUT TYPE=reset value='cancel'></TD></TR></table>";


这是我为更新查询编写的脚本。

    include 'db.php';
    $myfamname = $_POST['key2'];
    $myfirstname = $_POST['key3'];
    $access = $_POST['key4'];
    $erfahrungen = $_POST['erfahrungen_id'];
    $sch1 = ($_REQUEST['schulungen_id1']);
    $sch2  = ($_REQUEST['schulungen_id2']);
    $sch3  = ($_REQUEST['schulungen_id3']);
    $sch4  = ($_REQUEST['schulungen_id4']);
    $sch5  = ($_REQUEST['schulungen_id5']);
    $sch6  = ($_REQUEST['schulungen_id6']);
    $sch7  = ($_REQUEST['schulungen_id7']);
    $sch8  = ($_REQUEST['schulungen_id8']);
    $sch9  = ($_REQUEST['schulungen_id9']);
    $sch10  = ($_REQUEST['schulungen_id10']);

    $berec = 1;
    $schid= array(1,2,3,4,5,6,7,8,9,10);
    //$erid = array (1,2,3,4,5);
    $key1 = $_REQUEST['key1'];
    switch ($berec)
    {
    case 1 :
    if ((in_array($sch1,$schid)) && (in_array($sch2,$schid)) && (in_array($sch3,$schid)) && (in_array($sch4,$schid)) && (in_array($sch5,$schid)) && $erfahrungen == 2)
    {
    $berec = 2;
    }
    case 2 :
    if ((in_array($sch1,$schid)) && (in_array($sch2,$schid)) && (in_array($sch3,$schid)) && (in_array($sch4,$schid)) && (in_array($sch5,$schid)) && (in_array($sch6,$schid)) &&  (in_array($sch7,$schid))&& (in_array($sch8,$schid)) && $erfahrungen == 3)
    {
    $berec = 3;
    }
    case 3:
    if ((in_array($sch1,$schid)) && (in_array($sch2,$schid)) && (in_array($sch3,$schid)) && (in_array($sch4,$schid)) && (in_array($sch5,$schid)) && (in_array($sch6,$schid)) && (in_array($sch7,$schid))&& (in_array($sch8,$schid)) && (in_array($sch9,$schid)) &&  $erfahrungen == 4)
    {
    $berec = 4;
     }
    if ((in_array($sch1,$schid)) && (in_array($sch2,$schid)) && (in_array($sch3,$schid)) && (in_array($sch4,$schid)) && (in_array($sch5,$schid)) && (in_array($sch6,$schid)) && (in_array($sch7,$schid))&& (in_array($sch8,$schid)) && (in_array($sch9,$schid)) && (in_array($sch10,$schid)) &&  $erfahrungen == 5)
     {
     $berec = 5;
     }

     default : $access;
     break;
     }
     $update = "update driverlicense set berectigung_id= '$berec', erfahrungen_id='$erfahrungen',sicherheisunterweisung_id = 1,schulungen_id1 =  '$sch1',schulungen_id2 = '$sch2',schulungen_id3 = '$sch3',schulungen_id4 = '$sch4',schulungen_id5 = '$sch5',schulungen_id6 = '$sch6',schulungen_id7 = '$sch7',schulungen_id8 = '$sch8',schulungen_id9 = '$sch9',schulungen_id10 = '$sch10' where pers_nr = '$key1'";
     $q = mysql_query($update) or die(mysql_error());
     echo "<script>alert('Successfully Updated')</script>";
     echo "<script>location.href='view.php'</script>";
     echo "$sch5";

最佳答案

这可能是由于使用disabled = true引起的。

<INPUT TYPE=text name='schulungen_id1' value=$x7 disabled = true>


stackoverflow.com/questions/7244728/post-for-disabled-select-


  这就是禁用属性的工作方式。禁用表单控件后,提交表单时该值将被忽略,并且键不会出现在$ _POST(或$ _GET)中。
  
  如果您希望该值出现在提交的数据中,但又不希望用户更改页面上的值(我想这就是您要达到的目的),请使用readonly =“ readonly”代替of disabled =“ disabled”。


另请参见-https://stackoverflow.com/search?q=php+form+post+input+value+that+is+disabled

关于php - 更新查询,将零值写入数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13515130/

10-14 18:05