php - 值 1 存储在数据库中而不是文本框值/PHP-MySql

标签 php mysql

好吧,我想将 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/

相关文章:

php - 带有 jquery 的事件单选按钮

php - 将数据保存到Mysql后在PHP中使用AJAX显示DIV

php - Wordpress 无法连接到非常小的站点中的 DB : Too Many Connections,

PHP SQL SELECT 查询适用于除一个表之外的每个表

mysql - 为什么在 OpenCart 安装中不允许 MySQL root 用户?

php - Laravel 在 session 中存储数组

php - 在 PDO 中输出选择查询

sql - 两个内部连接 ​​MYSQL

php - mysql中的许多记录突然消失/丢失

php - Laravel Eloquent ORM 方法基于 ids 数组检索多行