好吧所以我使用的是PHP,我需要将文本框的内容放入我的数据库表中,当我点击提交时,不会抛出错误,但是这里没有任何内容放在我的代码中:
HTML:
<html>
<title>Chat App</title>
<head>
<link rel="stylesheet" type="text/css" href="chatCSS.css">
</head>
<body>
<div class="logOut">
<form action="loggedOut.php" method="POST">
<input type="submit" value="Log Out">
</form>
</div>
<div class="incomeMessages">
<input type="text" id="incomeMessageBox" disabled="disabled">
<br>
<br>
<form method="POST" action="index.php">
<input type="text" name="message" id="myMessage" placeholder="Message here...">
<input type="submit" id="myMessageSubmit">
</form>
</div>
</body>
</html>
PHP:
<?php
require 'includes/connect_mysql.php';
require 'includes/sessionCheck.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$message = $_POST['message'];
$time = time();
$user = $_SESSION['activeUser'];
if ($db_connect) {
$SQL = "INSERT INTO mainconversation (Name, Message, Time) VALUES ('$user', '$message', '$time')";
$result = mysqli_query($connection, $SQL);
mysqli_close($connection);
}
}
?>
连接代码:
<?PHP
$db_host = "localhost";
$db_username = "xxxx";
$db_pass = "xxxxxxxx";
$db_name = "chatapp";
$connection = mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
$db_connect = mysqli_select_db($connection, "$db_name") or die ("no database");
?>
答案 0 :(得分:2)
您没有检查错误,请尝试更改您的行$结果:
$result = mysqli_query($connection,$SQL) or die(mysqli_error($connection));
如果存在错误,您将收到错误。
答案 1 :(得分:0)
得到它,$user
变量已经包含' '
,所以当我把它们放在SQL中的变量时,它将它作为" "
感谢所有帮助!!!