我正在试图制作一个私人消息系统,用户可以在其中进行对话。每个对话都有其独特的散列。我想将消息存储在我的数据库中,但由于某种原因,散列值被存储为0而不是我请求的数字。
<form method="post" action="exiConversations.php" id="sendMessageFooterForm">
<input type="text" name="userNewMessage" id="userMessage" placeholder="Type een bericht" />
<input type="submit" name="sendNewMessageSubmit" id="sendMessageSubmit" value="Verzend" />
<?php
if (isset($_POST['sendNewMessageSubmit'])) {
$message = $_POST['userNewMessage'];
$fromUser = $_SESSION['userID'];
$today = date("y/m/d H:i:s");
$exiHash = $_GET['hash'];
$insertNewMessage = $conn->query("INSERT INTO messages (fromuser, messagedate, message, grouphash) VALUES ('$fromUser', '$today', '$message', '$exiHash')");
}
?>
</form>
我不知道该做什么了。它使用了var_dump($ exiHash);它显示我想要存储的散列号但它只存储一个0.
哪种类型的列'grouphash'它是否行得通呢? –
@ alexander.polomodov是的,我想将它存储在colum grouphash中 –
在提交到数据库之前,您确实需要'转义'您的变量。特别是因为你直接来自用户生成的网址。根据你使用的框架,我不确定正确的功能,但会像$ conn-> real_escape_string($变量),http://php.net/manual/en/function.mysql-real- escape-string.php – timothymarois