mongoDB中的PHP更新查询不工作
我正在尝试更新mongoDB中的一个数组。代码正在执行,没有错误,但文档没有更新 这是我的密码:mongoDB中的PHP更新查询不工作,php,mongodb,mongodb-php,Php,Mongodb,Mongodb Php,我正在尝试更新mongoDB中的一个数组。代码正在执行,没有错误,但文档没有更新 这是我的密码: <?php include 'connection.php'; session_start (); $username = $_SESSION ['username']; $collection = $database->selectCollection ( $username ); $books = $collection->find ( array ( '_i
<?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方法从不同的文件中获取了“id”,并进行了搜索
用于此文件中所需的文档。然后我引用了更新查询。但是
它不起作用
如果您从集合中选择单个文档,则应考虑使用,如果没有找到文档,则可以方便地返回第一个匹配文档(作为关联数组)或<代码> null < /代码>。这比使用
find()
创建游标并调用getNext()
更有效
乍一看,我认为表单无法正常工作,因为您没有正确地回显标识符值。引用你的例子:
<input type="hidden" name="id" id="id" value="<?php $id?>" />