为什么我一直收到通知:数组到字符串转换?

时间:2017-11-01 01:49:27

标签: php mysql

我正在尝试更新mysql数据库,但每次我都收到Notice:Array to string conversion。我真的无法弄清楚我在这里做错了什么。有人可以帮忙吗?

我的表格

<div class="panel-body">

<form role="form" method="post" action="client_post.php" class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-sm-3 control-label">Hospital No:
</label>

<div class="col-sm-5">
<input required  class="form-control" name="Hospital_no" placeholder="Patients' Hospital Number">
     </div>
     </div>

     <div class="form-group">
       <label class="col-sm-3 control-label">Date of New Status</label>

                                                          

                    <div class="form-group">
                        <label class="col-sm-3 control-label">New Status</label>

                        <div class="col-sm-5">
                            <select required name ="art_status" class="form-control">
                                <option></option>
                                <option value = "ART Restart" name="ART Restart">ART Restart</option>
                                <option value = "ART Transfer Out" name="ART Transfer Out" >ART Transfer Out</option>
                                <option value = "Pre ART Transfer Out" name="Pre ART Transfer Out">Pre ART Transfer Out</option>
                                <option value = "Lost to Followup" name="Lost to Followup">Lost to Followup</option>
                                <option value = "Stopped Treatment" name="Stopped Treatment">Stopped Treatment</option>
                                <option value = "Known Death" name="Known Death">Known Death</option>
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-sm-offset-3 col-sm-5">
                            <input class="btn btn-primary" type="submit" value="Update" name="submit" >

                        </div>
                    </div>
                </fieldset>
            </form>

我试图从此页面进行更新(client.php)

 if($_SERVER['REQUEST_METHOD'] === 'POST')
{


$Hosp_no = ['Hospital_no'];
$art_status = ['art_status'];
$art_date = ['art_start_date'];

$update_client = "UPDATE `pat_reg` SET  `art_status` = '$art_status', `art_start_date` = '$art_date'  WHERE `Hospital_no` = '$Hosp_no'";


if (mysqli_query($dbcon,$update_client))
{
    echo"<script>alert('Record Updated')</script>";
    //echo"<script>window.open('client_update.php','_self')</script>";
}


$dbcon->close();

}

请帮忙。

1 个答案:

答案 0 :(得分:3)

使用$_POST超全局允许您访问表单中提交的值。

更改以下内容:

$Hosp_no = ['Hospital_no'];
$art_status = ['art_status'];
$art_date = ['art_start_date'];

到此:

$Hosp_no = $_POST['Hospital_no'];
$art_status = $_POST['art_status'];
$art_date = $_POST['art_start_date'];

PS。您应该在查询数据库之前逃避用户的输入(或者,理想情况下,使用prepared statements),否则如果向公众发布,您可能会很快被黑客攻击。