本文介绍了我用PHP做错了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是我的php代码,其中包含我要提交给更新数据库的表单。 <!DOCTYPE html> < html > < head > < title > Chat-v1.0< / title > < / head > < body > < script src = https :// ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js\"> < / script > < script type = text / javascript > function submitChat(){ if (form1.uname .value == || form1.msg.value == ){ alert( 所有字段都是必需的!!!); return ; } var uname = form1.uname.value; var msg = form1.msg.value; var xml = new XMLHttpRequest(); xml.onreadystatechange = function (){ if ( xml.readyState == 4 && xml.status == 200 ){ document .getElementById(' chatlogs') .innerHTML = xml.responseText; } } xml.open(' GET', ' insert.php?uname =' + uname + ' & msg =' + msg, true ); xml.send(); } < / script > < 表单 方法 = POST 名称 = form1 onsubmit = return false; > 输入ChatName:< 输入 type = text name = uname > < br > 消息:< br > < textarea 姓名 = msg > < / textarea > < br > < 输入 名称 = button type = 提交 id = update value = 更新 onclick = submitChat() action = > < div id = chatlogs > 正在加载聊天记录,请稍候! ! < / div > < / form > < / body > < / html > 这是insert.php文件: 不会发生在数据库中。我能做错什么? 我的尝试: insert.php不起作用。我认为没有从表单中捕获方法。 if(isset($ _ POST ['' submit'])){ if ($ _SERVER [' REQUEST_METHOD'] == ' POST'){ echo pleaseeeeeeeee; $ uname = $ _ POST [' uname']; $ msg = $ _ POST [' msg']; $ username = 根; $ password = ; $ conn = new mysqli( localhost,$ username,$ password); mysql_select_db(' chatbox',$ conn); mysql_query( INSERT INTO logs('username','msg')值($ uname,$ msg )); $ result = mysql_query( SELECT * FROM logs ORDER by id DESC); while ($ exec = mysql_fetch_array($ result)){#code ... echo $ exec [' username']。 :。$ exec [' msg']。 < br>; } } } else { echo 糟糕; } ?> 解决方案 _POST [' submit'])){ if ( _SERVER [' REQUEST_METHOD'] == ' POST'){ echo pleaseeeeeeeee; uname = this is my php code with the form that I want to submit to update database.<!DOCTYPE html><html><head><title>Chat-v1.0</title></head><body><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script type="text/javascript">function submitChat(){if (form1.uname.value=="" || form1.msg.value=="") {alert("All fields are required!!!");return;}var uname=form1.uname.value;var msg = form1.msg.value;var xml = new XMLHttpRequest();xml.onreadystatechange=function(){if (xml.readyState==4 && xml.status==200) {document.getElementById('chatlogs').innerHTML=xml.responseText;}}xml.open('GET', 'insert.php?uname='+uname+'&msg='+msg,true);xml.send();}</script><form method="POST" name="form1" onsubmit="return false;">Enter ChatName: <input type="text" name="uname"><br>Message Here:<br><textarea name="msg"></textarea><br><input name = "button" type = "submit" id = "update" value = "Update" onclick="submitChat()" action = ""><div id="chatlogs">Loading Chats, Please Wait!!!</div></form></body></html>this is the insert.php file: Its not happen in the Database. What could I do wrong?What I have tried:The insert.php doesn't work. I think that not catch the method from the form.if(isset($_POST['submit'])) {if ($_SERVER['REQUEST_METHOD'] == 'POST') {echo "pleaseeeeeeeee";$uname=$_POST['uname'];$msg=$_POST['msg'];$username = "root";$password = "";$conn = new mysqli("localhost", $username, $password);mysql_select_db('chatbox',$conn);mysql_query("INSERT INTO logs('username', 'msg') Values($uname, $msg)");$result=mysql_query("SELECT * FROM logs ORDER by id DESC");while ($exec=mysql_fetch_array($result)) {# code...echo $exec['username'].":".$exec['msg']."<br>";}}}else{echo "its bad";}?> 解决方案 _POST['submit'])) {if (_SERVER['REQUEST_METHOD'] == 'POST') {echo "pleaseeeeeeeee";uname= 这篇关于我用PHP做错了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-07 04:06