菜鸟求教 PHP+JS

wojustsoso 2019-07-03 03:39:45
程序是php+mysql的,在阿里云运行时一切正常,输入客户编码后自动从数据库调取其他客户信息。php版本是5。



搬到新服务器后,php版本是7,输入客户编码后没任何反应。



日志仅有下面几条报错。

PHP Warning: implode(): Invalid arguments passed in /var/www/html/action.php on line 45

但我觉得这个不是原因

html源码

<form id="form1" name="form1" method="post" action="action.php?act=add" onsubmit="return check()">
<div class="hang_tit">Customer Information</div>
<div class="hang_item">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Customer No.:<span class="khxx"><input name="kehu" type="text" id="kehu" size="10" placeholder="" onblur="khxx(this)"/></span></td>
<td>Category:<span class="Category"></span></td>
<td>Grade:<span class="Grade"></span></td>
</tr>
<tr>
<td>Customer Name: <span class="khname"></span></td>
<td>Address: <span class="address"></span></td>
<td> </td>
</tr>
<tr>
<td>Contact Person: <span class="Person"></span></td>
<td>Email:: <span class="email"></span></td>
<td><span class=""></span></td>
</tr>
</table>


对应的JS代码

function khxx(obj){

khid=$(obj).attr("value");

//console.log(khid);

$.post("action.php?act=getKehu", { "khid": khid },

function(data){

//console.log(khid);

//$(obj).parents('tr').find('.pname').html(data.data[0].pname);

$(".Category").html(data.data[0].Category);

$(".Grade").html(data.data[0].Grade);

$(".khname").html(data.data[0].khname);

$(".address").html(data.data[0].address);

$("#d_address").val(data.data[0].address);

$(".Person").html(data.data[0].Person);

$(".email").html(data.data[0].email);

}, "json");

}


action.php

if($act=="getKehu"){

$sql_kh="select * from customer where CustomerNo='$khid'";

$result_kh=mysqli_query($GLOBALS['conn'], $sql_kh);

$info_kh=mysqli_fetch_array($result_kh);

$Category=$info_kh['Category'];

$Grade=$info_kh['Grade'];

$khname=$info_kh[2];

$address=$info_kh['Address'];

$Person=$info_kh['ContactPerson'];

$email=$info_kh['Email'];

echo '{"status" : 0 ,"msg" : "SUCCESS","data" :[{"Category":"'.$Category.'" ,"Grade" : "'.$Grade.'","khname" : "'.$khname.'","address" : "'.$address.'","Person" : "'.$Person.'","email" : "'.$email.'"},{"id" : 2,"name" : "xiaoming"}]}';

}


希望各位大神帮忙看看,谢谢。

如果代码问题比较严重的话可以有偿。
...全文
157 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wojustsoso 2019-08-21
  • 打赏
  • 举报
回复
知道原因了,没有关闭错误提示。
wojustsoso 2019-07-04
  • 打赏
  • 举报
回复
引用 7 楼 kang#kang 的回复:
console.log(data)

显示的是空的,用谷歌浏览器F12调试,console下是空的,这是不是说数据库连接有问题?
kang#kang 2019-07-03
  • 打赏
  • 举报
回复
console.log(data)
wojustsoso 2019-07-03
  • 打赏
  • 举报
回复
引用 4 楼 kang#kang 的回复:
你这一步测试 可以打印出sql执行的结果 然后 echo json_encode($info_kh)

然后在 js里面输入 console.log(data) 查看查询的结果 就知道错误在哪里了


$.post("action.php?act=getKehu", { "khid": khid },

function(data){

//console.log(khid);


我改成下面这样了,看不到结果啊。
function(data){

console.log(khid);
wojustsoso 2019-07-03
  • 打赏
  • 举报
回复
引用 4 楼 kang#kang 的回复:
你这一步测试 可以打印出sql执行的结果 然后 echo json_encode($info_kh)

然后在 js里面输入 console.log(data) 查看查询的结果 就知道错误在哪里了


$.post("action.php?act=getKehu", { "khid": khid },

function(data){

//console.log(khid);


方便加个微信吗?
kang#kang 2019-07-03
  • 打赏
  • 举报
回复
你这一步测试 可以打印出sql执行的结果 然后 echo json_encode($info_kh) 然后在 js里面输入 console.log(data) 查看查询的结果 就知道错误在哪里了 $.post("action.php?act=getKehu", { "khid": khid }, function(data){ //console.log(khid);
wojustsoso 2019-07-03
  • 打赏
  • 举报
回复
引用 2 楼 kang#kang 的回复:
你的data在console中打印出来是什么样子的 还有最后的json 为什么不用 echo json_encode ????

你的错误提示 在action.php的45行 你的implode 函数的参数不正确


感谢回复
implode的报错是后面其他代码相关的。
怎么测试这一步?

你的data在console中打印出来是什么样子的
kang#kang 2019-07-03
  • 打赏
  • 举报
回复
你的data在console中打印出来是什么样子的 还有最后的json 为什么不用 echo json_encode ???? 你的错误提示 在action.php的45行 你的implode 函数的参数不正确
wojustsoso 2019-07-03
  • 打赏
  • 举报
回复
日志里除了上面提到的Warning,再没有其他的报错了。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧