好吧,我想将 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>
最佳答案
您得到 bool 值而不是值本身。请记住,如果给定值存在,isset()
返回 true 并将其作为 1 存储在您的数据库中。
我猜你打算检查值是否存在,你可以像下面那样做:
$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 . '"');
}
希望对您有所帮助:)
关于php - 值 1 存储在数据库中而不是文本框值/PHP-MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55989266/