0
我正在通過從HTML表單提取數據來更新客戶詳細信息。數據庫的PHP查詢正在執行,但已更改的數據未反映在我的數據庫表中。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>
我想這是問題:'WHERE customer_id ='c_id'' –
我從會話變量中獲取'c_id',這個變量是正確的我已經驗證了它。 –
看看你對下面答案的評論,想想你可能是指'$ c_id'。正如查詢立即,'c_id'不是一個有效的PHP變量。另外,你應該考慮查看[MySQLi](http://php.net/manual/en/mysqli.prepare.php)和[PDO](http://php.net/manual/en/pdo.prepared- statement.php)_Prepared Statements_以防止您的代碼成爲[SQL注入攻擊]的簡單目標(http://stackoverflow.com/q/60174/2298301) –