值1存储在数据库中,而不是文本框值/ 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>


UYOU
浏览 165回答 3
3回答

慕盖茨4494581

您将获得布尔值,而不是值本身。请记住,如果给定值存在并且将其存储为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'])) {&nbsp; &nbsp; $sql_msg = mysqli_query($link, 'INSERT INTO messaging (title, message, sender, reciver) VALUES ("' . $title . '","' . $textareamsg . '","' . $Ccode . '","' . $reciver . '"');}希望对您有所帮助:)

梦里花落0921

好,谢谢大家。我确实尝试过,并且可以正常工作:$textareamsg = $_GET['textarea'];$title&nbsp; &nbsp; &nbsp; =&nbsp; $_GET['title'];$reciver&nbsp; &nbsp; =&nbsp; $_GET['reciver'];if (isset($_GET['sendmsg'])) {&nbsp; &nbsp; $sql_msg = mysqli_query($link, "INSERT INTO messaging (title, message, sender, reciver) VALUES ('$title','$textareamsg', '$ccode','$reciver')");}

侃侃无极

我认为您的单引号弄乱了您的查询语法。从这里开始,您的值必须在PHP中像这样引用$sql_msg&nbsp;=&nbsp;mysqli_query($link,&nbsp;"INSERT&nbsp;INTO&nbsp;messaging&nbsp;(title,&nbsp;message,&nbsp;sender,&nbsp;reciver)&nbsp;VALUES&nbsp;('$title',&nbsp;'$textareamsg',&nbsp;'$Ccode',&nbsp;'$reciver')";如果给定值存在并且将其存储在数据库中,则isset()返回true,其值为1
打开App,查看更多内容
随时随地看视频慕课网APP