gpt4 book ai didi

PHP 聊天室。不显示用户名,仅显示消息

转载 作者:行者123 更新时间:2023-11-29 07:18:30 28 4
gpt4 key购买 nike

我正在尝试使用 PHP 创建一个聊天室(顺便说一句,它正在工作),但只显示消息,而不显示他们的用户名。我已经为他们创建了数据库、用户名和消息。我不知道为什么他们的用户名没有显示

<? php

//$uname = $_REQUEST['uname'];
//$msg = $_REQUEST['msg'];

$uname = (isset($_REQUEST['uname']) ? $_REQUEST['uname'] : '');
$msg = (isset($_REQUEST['msg']) ? $_REQUEST['msg'] : null);





$con = mysql_connect('localhost', 'root', '');
mysql_select_db('chatbox', $con);

mysql_query("INSERT INTO logs (`username` , `msg`) VALUES ('$uname', '$msg')");

$result1 = mysql_query("SELECT * FROM logs ORDER by id DESC");

while ($extract = mysql_fetch_array($result1)) {
echo "<span class = 'uname'>".$extract['username'].
"</span>: <span class = 'msg'> ".$extract['msg'].
"</span><br/>";
}

?>
<?php $con=mysql_connect('localhost',
'root',
'');
mysql_select_db('chatbox',
$con);
$result1=mysql_query("SELECT * FROM logs ORDER by id DESC");
while($extract=mysql_fetch_array($result1)) {
echo"<span class = 'uname'>" . $extract['username'] ."</span>: <span class = 'msg'> " . $extract['msg'] ."</span><br/>";
}
?>
<?php ?>

<html>

<head>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<style>
* {
margin: 0;
}
body {
padding-right: 250px;
padding-left: 250px;
margin: 0;
background-color: darkkhaki;
}
textarea {
resize: none;
width: 100%;
height: 300px;
background-color: #efefef;
}
a {
background-color: cadetblue;
padding: 15px 25px 15px 25px;
text-decoration: none;
color: white;
}
a:hover {
background-color: chartreuse;
}
</style>
</head>

<body>
<form name="form1">
Enter your Username
<input type="text" name="uname">
<br/>Enter your Message
<br/>
<textarea name="msg"></textarea>
<br/>
<br/>
<a href="#" onclick="">Send</a>
<br/>
<br/>
<div id="chatlogs">
Loading Chat...
</div>
</form>

<script>
function submitChat() {
if (form1.uname.value == '' || form1.msg.value == '') {
alert('Please Input Username and Message');
return;
}

var uname = form1.uname.value;
var msg = form1.msg.value;
var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('chatlogs').innerHTML = xmlhttp.responseText;
}
}

xmlhttp.open('GET', 'insert.php?uname' + uname + '&msg=' + msg, true);
xmlhttp.send();

}
</script>
</body>

</html>

。错误之处欢迎指出。

最佳答案

替换

insert.php?uname

insert.php?uname=

更新的代码:

xmlhttp.open('GET', 'insert.php?uname=' + uname + '&msg=' + msg, true);

您没有插入 uname

关于PHP 聊天室。不显示用户名,仅显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37027425/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com