好吧,我想将 3 个文本框值存储到我的 mysqli 数据库中,运行这些代码后什么也没有发生!如果发生任何事情,那么数字“1”存储到数据库中而不是文本框值
PHP代码:
<?php
include 'displaycustomersdb.php'; //this file give $Ccode from user sessions and config.php is in it.
global $textareamsg;
global $title;
global $reciver;
global $sender;
$textareamsg = (isset($_GET['textarea']));
$title = (isset($_GET['title']));
$reciver = (isset($_GET['reciver']));
if (isset($_GET['sendmsg'])) {
$sql_msg = mysqli_query($link, 'INSERT INTO messaging (title, message, sender, reciver) VALUES (' . $title . ',' . $textareamsg . ',' . $Ccode . ',' . $reciver . '');
}
?>
HTML代码:
<?php include 'sendmsg.php'; ?>
<form method="get">
<i class="fas fa-envelope-open-text"></i><input type="text" placeholder="Ttitle here ..." name="title">
<br>
<br>
<i class="fas fa-user-plus"></i><input type="text" placeholder="TO" name="reciver">
<br>
<br>
<textarea rows="10" cols="100" placeholder="textarea" name="textarea" style="padding:10px;"></textarea>
<br>
<br>
<button type="submit" name="sendmsg"><i class="far fa-share-square"></i>Insert</button>
</form>
你得到的是布尔值而不是值本身。请记住,如果给定的值存在并且它作为1存储在您的数据库中,则isset()
返回true。我猜你打算检查值是否存在,你可以像下面那样做:
$textareamsg = isset($_GET['textarea'])? $_GET['textarea'] : '';
$title = isset($_GET['title'])? $_GET['title'] : '';
$reciver = isset($_GET['reciver'])? $_GET['reciver']: '';
而且你应该存储这样的字符串值:
if (isset($_GET['sendmsg'])) {
$sql_msg = mysqli_query($link, 'INSERT INTO messaging (title, message, sender, reciver) VALUES ("' . $title . '","' . $textareamsg . '","' . $Ccode . '","' . $reciver . '"');
}
希望它会有所帮助:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句