我有两个问题。我有一个表单没有将数据插入数据库,我有一个没有更新的更新查询。更新查询不与表单一起使用。它应该在你去页面时自动更新。我的猜测是他们都有同样的问题。我在两者中都包含了我的配置。每件事都占了。我已经尝试过bindValue。如果您需要更多信息,请在下面评论并询问。我通常不喜欢在这里发帖,因为你们中的一些人可能会因为不包含信息或其他东西而有点苛刻。我愿意和你们任何人合作。感谢您的帮助!
PHP for Form:
<?php
if (isset($_POST['submit'])) {
$touser = $_POST['ToUser'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$from = $usersession;
$timestamp = date("Y/m/d H:i:s");
$read = 0;
$trash = 0;
if (empty($touser) || empty($subject) || empty($message)) {
echo "<b>Please fill out all fields</b>";
} else {
$query = $db->prepare("INSERT INTO Messaging (ToUser,Subject,Message,FromUser,Timestamp,Read,Trash) VALUES (:ToUser,:Subject,:Message,:FromUser,:Timestamp,:Read,:Trash)");
$query->bindParam(':ToUser', $touser);
$query->bindParam(':Subject', $subject);
$query->bindParam(':Message', $message);
$query->bindParam(':FromUser', $from);
$query->bindParam(':Timestamp', $timestamp);
$query->bindParam(':Read', $read);
$query->bindParam(':Trash', $trash);
$query->execute();
echo "<b>Message Sent</b>";
}
}
?>
将HTML表单改为:
<form method="post" class="form-horizontal form-bordered">
<div class="form-group">
<label class="col-md-3 col-lg-2 control-label" for="compose-to">To</label>
<div class="col-md-9 col-lg-10">
<input type="text" id="compose-to" name="ToUser" class="form-control form-control-borderless" placeholder="Enter a Username">
</div>
</div>
<div id="cc-input" class="form-group display-none">
<label class="col-md-3 col-lg-2 control-label" for="compose-to-cc">Cc</label>
<div class="col-md-9 col-lg-10">
<input type="email" id="compose-to-cc" name="compose-to-cc" class="form-control form-control-borderless" placeholder="Enter Cc emails..">
</div>
</div>
<div id="bcc-input" class="form-group display-none">
<label class="col-md-3 col-lg-2 control-label" for="compose-to-bcc">Bcc</label>
<div class="col-md-9 col-lg-10">
<input type="email" id="compose-to-bcc" name="compose-to-bcc" class="form-control form-control-borderless" placeholder="Enter Bcc emails..">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-lg-2 control-label" for="compose-subject">Subject</label>
<div class="col-md-9 col-lg-10">
<input type="text" id="compose-subject" name="Subject" class="form-control form-control-borderless" placeholder="Your subject..">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-lg-2 control-label" for="compose-message">Message</label>
<div class="col-md-9 col-lg-10">
<textarea id="compose-message" name="Message" rows="20" class="form-control textarea-editor" placeholder="Your message.."></textarea>
</div>
</div>
<div class="form-group form-actions">
<div class="col-md-9 col-md-offset-3 col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-sm btn-primary"><i class="fa fa-share"></i> Send</button>
<!-- Uncomment for draft button
<button type="button" class="btn btn-sm btn-default"><i class="fa fa-pencil"></i> Save Draft</button>
-->
</div>
</div>
</form>
继承更新部分:
<?php
$id = $_GET['id'];
$read = 1;
$query = $db->prepare('UPDATE Messaging SET Read = :read WHERE Id = :id');
$query->bindParam(':id', $id);
$query->bindParam(':read', $read);
$query->execute();
?>
我把它弄清楚了。我在所有的字段中添加了``并且它有效。无论如何,谢谢你的帮助!