douaoli5328 2017-07-20 18:37
浏览 63

使用mysql服务器和PHP更新数据库上的值

I was wondering if someone could point me on the right path here. There's a database with fields: PersonID, FirstName, LastName, isActive.

I collect those values from a form:

<form action="" method="POST" id="myForm"><input type="hidden" name="hdnId" id="hdnId" value="<?php echo $var_PersonID?>">

First Name<br>
<input type="text" name="txt_first_name" id="txt_first_name" value="<?php echo $var_FirstName;?>">
Last Name<br>
<input type="text" name="txt_last_name" id="txt_last_name" value="<?php echo $var_LastName;?>">
  Status <br>
    <select name="status" id="status">
<option value=""  > </option>
<option value="1" >Active</option>
<option value="2" >Inactive</option>
   </select>
   </form>

The PHP code when submit the form looks like this:

<?php
        if(isset($_POST['Save']) || isset($_POST['Saveexit']))
        {
            $var_PersonID        = $_POST['hdnId'];
            $var_FirstName       = $_POST['txt_first_name'];
            $var_LastName        = $_POST['txt_last_name'];
            $var_IsActive        = $_POST['status'];
              if($var_PersonID!='')
          {
              $sql = "UPDATE vw_Persons SET FirstName, LastName, isActive = ?  WHERE PersonID  = $var_PersonID ";



              $params = array($var_FirstName, $var_LastName,$var_IsActive);


              $stmt = sqlsrv_query( $gaSql['link'], $sql, $params); 
       }
     }  ?>

Once the page is loaded I grab values like this:

enter code here
 <?php
         if(isset($_GET['id']))
          {
        $query = "SELECT * FROM vw_Persons WHERE PersonID = '" . $_GET['id'] . "'";
    $result = sqlsrv_query($gaSql['link'], $query) or die("<pre>" . print_r(sqlsrv_errors()) . "<br><br>$query</pre>");
    $obj = sqlsrv_fetch_object( $result );

    $var_PersonID        = $obj->PersonID;
    $var_LastName        = $obj->LastName;
    $var_FirstName       = $obj->FirstName;
    $var_IsActive       = $obj->isActive;

  }  ?>

So the query updates the FirstName and Last Name values but no the isActive value, why would this happen?

  • 写回答

1条回答 默认 最新

  • douren9077 2017-07-21 03:13
    关注

    well since the isActive field was a bit type field it only accepts values of 1 and 0 so I changed it to <option value="0" >Inactive</option> and it worked

    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败