数据未更新。我怎样才能解决这个问题?

时间:2019-12-17 02:02:47

标签: php html mysql forms input

我有一个问题,由于某种原因数据没有被更新。我尝试了多种方法,但似乎没有任何解决方法。知道为什么不更新数据吗?麻烦在下面发布我的所有代码。

编辑页面

<?php 
    require_once("config.php"); //this file connects to my db and works 100%
    $iD = $_GET['GetID'];
    $query = "SELECT * FROM db WHERE Id='".$iD."'";

    $result = mysqli_query($conn, $query);

    while($row=mysqli_fetch_assoc($result))
    {
        $id = $row['Id'];
        $name = $row['Name'];
        $date = $row['Birthdate'];
        $phonenumber = $row['PhoneNumber'];
        $sex = $row['Sex'];
        $weight = $row['Weight'];
        $height = $row['Height'];
        $emergencycontactname = $row['EmergencyContactName'];
        $emergencycontactnamephonenumber = $row['EmergencyContactNamePhoneNumber'];
        $medicalissues = $row["MedicalIssues"];
    }

?>
<html>
    <head>
            <title>Medical DataBase</title>
            <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
            <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    </head>
    <body>
              <h2 id="title" class="text-center">Medical Database</h2>
                <form id="form" method="POST" action="update.php?ID=<?php echo $id ?>">
                        <div class="form-row">

                            <div class="form-group col-md-3">
                                <label for="Name">Full Name of the Person: </label>
                            <input type="text" class="form-control" name="Name" id="Name" value="<?php echo $name?>">
                            </div>

                              <div class="form-group col-md-3">
                                <label for="Date">Birthdate:</label>
                                <input type="text"  name="Date" class="form-control" id="Date" placeholder="MM/DD/YY" value="<?php echo $date?>">
                              </div>

                            <div class="form-group col-md-3">
                                    <label for="personPN">Phone Number: </label>
                                    <input type="text" class="form-control" name="personPN" id="personPN" placeholder="(XXX)XXX-XXXX" value="<?php echo $phonenumber?>">
                            </div>
                            <div class="form-group col-md-3">
                                    <label for="Sex">Sex</label>
                                    <input type="text" class="form-control" id="Sex" name="Sex" value="<?php echo $sex?>">
                            </div>
                            <div class="form-group col-md-3">
                                    <label for="Weight">Weight</label>
                                    <input type="text" class="form-control" name="Weight" id="Weight" placeholder="Weight lbs" value="<?php echo $weight?>">
                            </div>
                            <div class="form-group col-md-3">
                                    <label for="Height">Height</label>
                                    <input type="text" class="form-control" name="Height" id="Height" placeholder="X'X" value="<?php echo $height?>">
                            </div>
                            <div class="form-group col-md-3">
                              <label for="ECN">Emergency Contact Name: </label>
                              <input type="text" class="form-control" name="ECN" id="ECN" value="<?php echo $emergencycontactname?>">
                      </div>
                      <div class="form-group col-md-3">
                              <label for="ECPN">Emergency Contact Name Phone Number: </label>
                              <input type="text" class="form-control" name="ECPN" id="ECPN" placeholder="(XXX)XXX-XXXX" value="<?php echo $emergencycontactnamephonenumber?>">
                      </div>

                        </div>

                              <div class="form-group">
                                    <label for="MedicalIssues">Medical Issues</label>
                                    <input type="text" class="form-control" id="MedicalIssues" name="MedicalIssues" rows="3" value="<?php echo $medicalissues?>">
                                </div>

                        </div>

                        <div class="form-row">
                                <div class="form-group col-md-12 text-right">
                                    <button id="button" name="update" type="submit" class="btn btn-primary">Update</button>
                                </div>
                            </div>
                </form>
    </body>
    </html>

在下面更新PHP代码

<?php

    require_once("config.php");

    if(isset($_POST['update']))
    {
        $id = $_GET['Id']; 
        $name = $_POST['Name'];
        $date = $_POST['Birthdate'];
        $phonenumber = $_POST['PhoneNumber'];
        $sex = $_POST['Sex'];
        $weight = $_POST['Weight'];
        $height = $_POST['Height'];
        $emergencycontactname = $_POST['EmergencyContactName'];
        $emergencycontactnamephonenumber = $_POST['EmergencyContactNamePhoneNumber'];
        $medicalissues = $_POST["MedicalIssues"];

        $query = "UPDATE db SET Name ='".$name."', Birthdate ='".$date."', PhoneNumber ='".$phonenumber."', Sex ='".$sex."', Weight ='".$weight."', Height ='".$height."', EmergencyContactName ='".$emergencycontactname."', EmergencyContactNamePhoneNumber ='".$emergencycontactnamephonenumber."', MedicalIssues ='".$medicalissues."' WHERE Id='".$id."'";

        $result = mysqli_query($conn,$query);

        if($result)
        {
            header("location:view.php"); //redirects me here but does not update data
        }
        else{
            echo "Please Check your query";
            echo "<br>";
            echo $query;
        }
    }
    else
    {
        header("location:view.php");
    }
?>

所以是的,我不确定它的查询是否错误,但是它只是将我重定向到我的view.php文件,并且我尝试了多种操作,例如更改重定向以查看哪个正在工作,并将其发送到包含变量结果的if语句。任何线索为什么它不起作用?我觉得查询是正确的。

0 个答案:

没有答案