doubian19900911
2016-09-16 09:12
浏览 23
已采纳

PHP无法更新数据库,提交后没有任何反应[关闭]

This is my form page

<?php     $result= mysql_query("SELECT * FROM Staff WHERE StaffID = 1");

while ($myrow=mysql_fetch_assoc($result))
{

$PName=$myrow['PName'];
$PGender=$myrow['PGender'];
$PCoNum=$myrow['PCoNum'];
$PEmail=$myrow['PEmail'];
$PID=$myrow['PID'];
$PNat=$myrow['PNat'];
$PAdd=$myrow['PAdd'];
$PSal=$myrow['PSal'];
}
?>
  <form action="SavePProfile.php" method="POST">
    <div class="form-group">
      <label for="PName" class="col-sm-2 control-label">Name: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PName; ?>" id="PName">
      </div>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PGender" class="col-sm-2 control-label">Gender: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PGender; ?>" id="PGender">
      </div>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PCoNum" class="col-sm-2 control-label">Contact No: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PCoNum; ?>" id="PCoNum">
      </div>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PEmail" class="col-sm-2 control-label">Email Address: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PEmail; ?>" id="PEmail">
      </div>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PID" class="col-sm-2 control-label">IC/Passport No: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PID; ?>" id="PID">
      </div>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PNat" class="col-sm-2 control-label">Nationality: </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PNat; ?>" id="PNat">
      </div>
    </div>
    <br></br>
    <div class="form-inline">
      <label for="PAdd" class="col-sm-2 control-label">Address: </label>
      <textarea class="form-control" rows="5" cols="68" id="PAdd"><?php echo $PAdd; ?></textarea>
    </div>
    <br></br>
    <div class="form-group">
      <label for="PSal" class="col-sm-2 control-label">Salary (Monthly): </label>
      <div class="col-sm-5">
        <input type="text" class="form-control" value= "<?php echo $PSal; ?>" id="PSal">
      </div>
    </div>
    <br></br>
  <button type="submit" class="btn btn">Save</button>
  <button type="submit" class="btn btn" onclick="location.href='HomePage.php';">Back</button>
  </form>

While this is my update process

  <?php    if (isset($_POST['PName']))
  {
      $PName=$_POST['PName'];
      $PGender=$_POST['PGender'];
      $PCoNum=$_POST['PCoNum'];
      $PEmail=$_POST['PEmail'];
      $PID=$_POST['PID'];
      $PNat=$_POST['PNat'];
      $PAdd=$_POST['PAdd'];
      $PSal=$_POST['PSal'];




      $UpdateProfile="UPDATE Staff
      SET PName= '$PName', PGender= '$PGender', PCoNum= '$PCoNum', PEmail='$PEmail', PID='$PID', PNat='$PNat', PAdd='$PAdd', PSal='$PSal'
      WHERE StaffID=1";

      if (empty ($_POST['PName'])||empty ($_POST['PGender'])||empty ($_POST['PCoNum'])||empty ($_POST['PEmail'])||empty ($_POST['PID'])||empty ($_POST['PNat'])||empty ($_POST['PAdd'])||empty ($_POST['PSal']))
        {
            echo '<div class="callout callout-danger">
            <h4>Notice!</h4>
            <p>Unable to save!</p>
            </div>';
        }
        else 
        {
            mysql_query($UpdateProfile);

            echo '<div class="callout callout-success">
            <h4>Notice!</h4>
            <p>User saved.</p>
            </div>';
        }


  }
  ?>
  <br></br>

The data was able to show up in the form page,but when i try clicking "save" button, nothing happen, no notice no error, can someone tell me where went wrong?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douzhimao8656 2016-09-16 09:15
    最佳回答

    None of your inputs have name attributes, you should change :

    <input type="text" class="form-control" value= "<?php echo $PName; ?>" id="PName">
    

    With :

    <input type="text" class="form-control" value= "<?php echo $PName; ?>" name="PName">
    

    And so on.

    EDIT : And of course, you should never use mysql_* functions, as explained here.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题