PHP查询数据库更新成功执行但值未在数据库表上更新

时间:2017-04-01 20:34:06

标签: php mysql

我通过从html表单中获取数据来更新客户详细信息。正在执行数据库的PHP查询,但更改的数据未反映在我的数据库表中。

PHP代码:

从表单

获取数据的代码
$con = mysqli_connect("localhost","root","","ecommerce");
    if(isset($_POST['savec']))
    {
        global $con;

        $name=$_POST['name'];
        $phone=$_POST['phone'];
        $email=$_POST['email'];
        $passm=$_POST['password'];
        $pass=md5($passm);
        $cust_query="UPDATE er_customer SET customer_name='$name',customer_phone='$phone',customer_email='$email',customer_password='$pass' WHERE customer_id='c_id'";
        $excecute=mysqli_query($con,$cust_query);

        if($excecute)
        {
            echo "<script> alert('Account changes is successfull.') </script>";
        }
    }

表格代码:

>    <form method="post" class="registration-form"
> action="account_settings.php" id="form_login"
> enctype="multipart/form-data">
>                       
>                   <div class="form-group">
>                         <label>Name</label>
>                            <input class="form-control"  name="name" type="text" value="<?php echo"$c_name"; ?>" required>                 
> 
>                     </div>         
>                   
>                   <div class="form-group">
>                         <label>Phone</label>
>                            <input class="form-control" name="phone" type="text" value="<?php echo"$c_phone"; ?>" required>                
> 
>                     </div>
>                   
>                   
>                   <div class="form-group">
>                         <label>Email</label>
>                            <input class="form-control" name="email" type="text" value="<?php echo"$c_email"; ?>" required>                
> 
>                     </div>
>               
>                   
>                   <div class="form-group">
>                         <label>Password</label>
>                            <input class="form-control" name="password" type="text" value="" required>                       
>                     </div>
>               
>                   </br>
>                   
>                   <div class="form-group">
>                        
>                            <input type="submit" class="col-sm-3 btn btn-success" name="savec" value="Save changes" align="center" />      
> 
>                     </div>
>               
>               
>               </form>

1 个答案:

答案 0 :(得分:0)

尝试更改您的更新查询,如下所示:

$cust_query="UPDATE er_customer SET customer_name=$name,customer_phone=$phone,customer_email=$email,customer_password=$pass WHERE customer_id=$c_id";

确保通过调试正确获取的所有变量值