Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用$\u GET变量插入数据库_Php_Mysqli - Fatal编程技术网

Php 使用$\u GET变量插入数据库

Php 使用$\u GET变量插入数据库,php,mysqli,Php,Mysqli,我正在尝试建立一个私人信息系统,用户可以在其中进行对话。每个会话都有其唯一的散列。我想将消息存储在数据库中,但由于某种原因,哈希值被存储为0,而不是我请求的数字 <form method="post" action="exiConversations.php" id="sendMessageFooterForm"> <input type="text" name="userNewMessage" id="userMessage" placeholder="Type ee

我正在尝试建立一个私人信息系统,用户可以在其中进行对话。每个会话都有其唯一的散列。我想将消息存储在数据库中,但由于某种原因,哈希值被存储为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>


更改表单标记中的操作属性。 它一定是我喜欢的


action=“exiConversations.php?”
哪种类型的列
grouphash
?@alexander.polomodov是的,我想将其存储在columgrouphash中在提交到数据库之前,您确实需要
转义您的变量。特别是因为您直接来自用户生成的URL。根据您所使用的框架,我不确定是否使用了正确的函数,但类似于$conn->real\u escape\u string($variable),同样对于0,在
grouphash
列上的数据库设置是为了什么?是
int
?如果您需要将其更改为
char
varchar
,我猜它只允许整数。从您的代码中,我看不出在提交表单时如何设置
$\u GET['hash']
。“但只有当您具有当前URL时,它才会起作用,如……?hash=45345”-这不完全正确。这可能来自预取的db查询。是的,你是对的。或来自会话变量。或其他POST变量(如果此页面是从表单加载的)。许多变体:)