我正在構建一個項目,出於某種原因,我無法讓我的Update語句實際更新。mysqli update update not update eventhough stating successful?
我在表單中有一些輸入字段,它提供了下面變量的詳細信息。
這裏是我的代碼:
//update database
$stmt = $mysqli->prepare("UPDATE pages SET
pg_name= ?,
pg_title = ?,
pg_keywords = ?,
pg_description = ?,
pg_header1 = ?,
pg_header2 = ?,
pg_maintext = ?,
pg_active = ? WHERE id = ?");
$stmt->bind_param('sssssssii',
$pg_name,
$pg_title,
$pg_keywords,
$pg_description,
$pg_header1,
$pg_header2,
$pg_maintext,
$pg_active,
$id);
if($stmt->execute() === TRUE){
$stmt->close();
echo "Database successfully updated";
} else {
echo "There was a problem updating the database.";
}
我已經測試和變量正在從我的表單中設置好,當我運行該腳本,我得到了「成功」的消息,但檢查我的數據庫,並沒有任何事情發生。
我錯過了什麼? :)
感謝您的幫助/
OK <低於現有表單/表:
<form action="" method="post">
<table>
<tr>
<td colspan="2"><?php echo "<span style='color: red; font-weight: bold;'>".$errmsg."</span><br />"; ?></td>
</tr>
<tr>
<td>Page Name:</td>
<td><input type="text" name="pg_name" id="pg_name" value="<?php if(isset($id)){ echo $page['pg_title']; }?>" /></td>
</tr>
<tr>
<td>Page Title:</td>
<td><input type="text" name="pg_title" id="pg_title" value="<?php if(isset($id)){ echo $page['pg_title']; }?>" /></td>
</tr>
<tr>
<td>Keywords:</td>
<td><input type="text" name="pg_keywords" id="pg_keywords" value=" <?php if(isset($id)){ echo $page['pg_keywords']; }?>" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" name="pg_description" id="pg_description" value="<?php if(isset($id)){ echo $page['pg_description']; }?>"/></td>
</tr>
<tr>
<td>Main page header:</td>
<td><input type="text" name="pg_header1" id="pg_header1" value="<? php if(isset($id)){ echo $page['pg_header1']; }?>"/></td>
</tr>
<tr>
<td>Subheader:</td>
<td><input type="text" name="pg_header2" id="pg_header2" value="<? php if(isset($id)){ echo $page['pg_header2']; }?>" /></td>
</tr>
<tr>
<td>Page text</td>
<td><textarea name="pg_maintext" id="pg_maintext"><?php if(isset($id)){ echo $page['pg_maintext']; }?></textarea></td>
</tr>
<tr>
<td>Active?</td>
<td><select name="pg_active">
<option value="1">Yes</option>
<option value="0">No</option>
</select></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="<?php if(isset($_GET['page_id'])){ echo "Update"; } else { echo "Add"; } ?>" /><?php if(isset($_GET['page_id'])){ echo "<a href='pages.php' /><input type='button' name='new' id='new' value='New' /></a>"; } ?></td>
<td></td>
</tr>
</table>
</form>
我試圖在我的數據庫直接的SQL表彰,和它的作品。只是不通過這種形式工作。數據庫已連接並且表單能夠從數據庫中提取數據。
更新:我試過了我所想的一切 - 這裏沒有任何工作。我爲每個步驟添加了錯誤報告,並且因爲它認爲沒有錯誤,所以沒有錯誤發生!我隨時都可以更新對SQL的訪問權限。
你能否提供表格結構? –
沒有函數'PDOStatement :: close()'。可能不是什麼原因導致你的錯誤,但仍應該糾正。 – TheWolf
嘗試使用確切參數在MySql中運行相同的查詢,並查看它是否成功。 –