我的數據庫沒有更新,沒有顯示任何錯誤,任何人? 我已經設置了$ id和所有變量,但是如果我在查詢中做錯了什麼,請問可以嗎? 預先感謝您SQL查詢不更新數據庫
PHP代碼
<?php
//get values from Database for user
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
$result = mysql_query("SELECT * FROM Credentials, Company WHERE Credentials.ID = $id AND Company.CompanyID = $id") or trigger_error(mysql_error());
$row = mysql_fetch_array($result);
}
if (isset($_POST['submitted'])) {
//define index for variables
if(isset($_POST['email'])){
$email = $_POST['email'];
}
if(isset($_POST['password'])){
$password = $_POST['password'];
}
if(isset($_POST['permission'])){
$permission = $_POST['permission'];
}
if(isset($_POST['status'])){
$status = $_POST['status'];
}
//safe input for all fields
$email = safe_input($email);
$password = safe_input($password);
$permission = safe_input($permission);
$status = safe_input($status);
//double checking inputs
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }
//SQL queries
$sql = mysql_query("UPDATE Credentials SET `Email` = '".$email."' , `Password` = '".$password."' , `Permission` = '".$permission."', `Status` = '".$status."' WHERE `ID` = $id ") or die(mysql_error());
echo "<div id='add-success'><i class='fa fa-check'></i> <b>Updated Successfuly!</b></div><br/>";
}
?>
HTML
<form action='edit.php?id=<?php echo safe_input($id); ?>' method='POST' id="add-merchant" enctype="multipart/form-data">
<p><br />
<h6>Email</h6>
<input type='text' name='email' value="<?php echo nl2br($row['Email']); ?>"
onfocus="if (this.value==this.defaultValue) this.value = ''"
onblur="if (this.value=='') this.value = this.defaultValue"/>
<p><br />
<h6>Enter New Password</h6>
<input type='text' name='password' value='Password'
onfocus="if (this.value==this.defaultValue) this.value = ''"
onblur="if (this.value=='') this.value = this.defaultValue"/>
<p><br />
<h6>Permission</h6>
<select name="permission">
<option value="0" selected>Unverified</option>
<option value="1">Verified</option>
</select>
<p><br />
<h6>Status</h6>
<select name="status">
<option value="1" selected>Activated</option>
<option value="0">Deactivated</option>
</select>
<p><input type='submit' value='Update' /><input type='hidden' value='1' name='submitted' />
</form>
做一些'如果執行在'if'聲明腳本echo'測試 – 2014-09-21 09:32:36
檢查'if'滿足條件還是不行! – MH2K9 2014-09-21 09:32:49
我已經設置了回聲聲明沒有錯誤,查詢成功,它顯示「已成功更新」 – 2014-09-21 09:45:11