Я пытаюсь обновить массив в mongoDB, код выполняется без ошибки, но документ не обновляется.PHP update query in mongoDB не работает
вот мой код:
<?php
include 'connection.php';
session_start();
$username = $_SESSION ['username'];
$collection = $database->selectCollection ($username);
$books = $collection->find (array (
'_id' => new MongoId ($_POST ['id'])
));
$book = $books->getNext();
$imgid = $book ['imgid'];
$id = $book['_id'];
if (isset ($_POST ['formsubmit'])) {
$gridFS = $database->getGridFS();
// if (isset ($_FILES ['pic']))
// $imgid = $gridFS->storeUpload ('pic', array (
// "username" => $username
//));
$collection->update (array (
"_id" => new mongoId ($id)
), array (
'$set' => array (
'bookname' => $_POST ['bookname'],
'authname' => $_POST ['authname'],
'pubname' => $_POST ['pubname'],
'imgid' => $imgid,
'cost' => $_POST ['cost']
)
));
echo '<h3>File Updated Successfully</h3>';
}
$mongo->close();
?>
<html>
<head>
<title>Online Book Exchange::Exchange old/Used books</title>
<link rel="icon" href="images/favicon.ico">
<link href="style/own.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container_box">
<div class="navbar">
<p>
<a href="session.php">Dash Board</a> | <a
href="logout.php"
onClick="return confirm('Are you sure you want to Logout?')">Logout</a>
</p>
</div>
<br> <br>
<div class="motofont">
<h3>
<img src="images/LogoShortMedium.png" alt="Online book store"
width="162" height="39" /> Edit Book
</h3>
<hr>
</div>
<br> <br>
<div id="errorBox"></div>
<form name="form" method="POST" enctype="multipart/form-data"
action="editbook.php">
<table width="60%" cellspacing="2" cellpadding="5" align="center">
<tr>
<td>
<div class="reg_font">Book Name :</div>
</td>
<td><input type="text" name="bookname" id="bookname" class="txt"
value="<?php echo $book['bookname']; ?>" /></td>
</tr>
<tr>
<td>
<div class="reg_font">Author Name:</div>
</td>
<td><input type="text" name="authname" id="authname" class="txt"
value="<?php echo $book['authname']; ?>" /></td>
</tr>
<tr>
<td>
<div class="reg_font">Publication Name:</div>
</td>
<td><input type="text" name="pubname" id="pubname" class="txt"
value="<?php echo $book['pubname']; ?>" /></td>
</tr>
<tr>
<td>
<div class="reg_font">Cost</div>
</td>
<td><input type="text" name="cost" id="cost" class="txt"
value="<?php echo $book['cost']; ?>" /> <input type="hidden"
name="id" id="id" value="<?php $id?>" /></td>
</tr>
<tr>
<td><div class="reg_font">Upload an Image:</div></td>
<td><input type="file" name="pic" id="pic" class="btn_2" /></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><button
type="submit" value="Register" name="formsubmit" id="formsubmit" class="btn">Edit</button></td>
</tr>
</table>
</form>
<hr>
</div>
</body>
</html>
я принял «идентификатор» из другого файла метод POST и искал требуемый документ в этом файле. затем я процитировал запрос на обновление. но его не работает
, а также как проверить, выбрано ли изображение в форме? Я хочу заменить существующее изображение, если загружено новое изображение.
заранее спасибо