本来在另外一台电脑上wamp2.4 win7 完全可以运行,现在换了台电脑,wamp3.0 win10 就不能运行了,为什么啊?是不是配置没配好
以下代码
html:
姓名:
*
电话:
*
身份证 :
*
医保卡 :
住院号 :
住址:
联系人姓名:
联系人电话:
js:
$('#add_user').validate({
submithandler:function(form){
$('#add_user').ajaxsubmit({
url:thinkphp['module']+'/user/add',
type:'post',
success:function(data){
alert(data);
$('#name').val();
$('#phone').val();
$('#id_card').val();
$('#health_card').val();
$('#contact_name').val();
$('#contact_phone').val();
},
});
},
rules:{
name:{
required:true,
},
age:{
required:true,
},
phone:{
required:true,
},
id_card:{
required:true,
},
},
messages:{
name:{
required:'姓名不得为空',
},
age:{
required:'年龄不得为空',
},
phone:{
required:'电话不得为空',
},
id_card:{
required:'身份证不得为空',
},
},
});
控制器:
public function add(){
$user=d('user');
$id=$user->add(i('post.name'),i('post.phone'),i('post.id_card'),i('post.health_card'),i('post.hospitalized'),i('post.address'),i('post.contact_name'),i('post.contact_phone'));
echo $id?$id:0;
}
model:
public function add($name,$phone,$id_card,$health_card,$hospitalized,$address,$contact_name,$contact_phone){
//$身份证号 = '';
$birth = strlen($id_card)==15 ? ('19' . substr($id_card, 6, 6)) : substr($id_card, 6, 8);
$birth=substr($birth,0,4).'-'.substr($birth,4,2).'-'.substr($birth,6,2);
list($year,$month,$day) = explode(-,$birth);
$year_diff = date(y) - $year;
$month_diff = date(m) - $month;
$day_diff = date(d) - $day;
if ($day_diff $year_diff--;
$age=$year_diff;
$sex = substr($id_card, (strlen($id_card)==15 ? -1 : -2), 1) % 2 ? '男' : '女';
$data=array(
'name'=>$name,
'age'=>$age,
'sex'=>$sex,
'phone'=>$phone,
'id_card'=>$id_card,
'health_card'=>$health_card,
'hospitalized'=>$hospitalized,
'address'=>$address,
'contact_name'=>$contact_name,
'contact_phone'=>$contact_phone,
);
return m('user')->add($data);
}
火狐报错:post xhr http://localhost/aier/index.php/home/user/add [http/1.1 404 not found 35ms]
:(
1146:table 'aier.u' doesn't exist [ sql语句 ] : replace into `u` () values ()
错误位置
file: d:\wamp64\www\aier\thinkphp\library\think\db\driver.class.php line: 350
trace
#0 d:\wamp64\www\aier\thinkphp\library\think\db\driver.class.php(350): e('1146:table 'aie...')
#1 d:\wamp64\www\aier\thinkphp\library\think\db\driver.class.php(237): think\db\driver->error()
#2 d:\wamp64\www\aier\thinkphp\library\think\db\driver.class.php(824): think\db\driver->execute('replace into `u...', false)
#3 d:\wamp64\www\aier\thinkphp\library\think\model.class.php(320): think\db\driver->insert('3424', 'u24234', '24323423')
#4 d:\wamp64\www\aier\app\home\controller\usercontroller.class.php(12): think\model->add('3424', '324234', '24323423', '', '', '', '', '')
#5 [internal function]: home\controller\usercontroller->add()
#6 d:\wamp64\www\aier\thinkphp\library\think\app.class.php(173): reflectionmethod->invoke(object(home\controller\usercontroller))
#7 d:\wamp64\www\aier\thinkphp\library\think\app.class.php(110): think\app::invokeaction(object(home\controller\usercontroller), 'add')
#8 d:\wamp64\www\aier\thinkphp\library\think\app.class.php(204): think\app::exec()
#9 d:\wamp64\www\aier\thinkphp\library\think\think.class.php(120): think\app::run()
#10 d:\wamp64\www\aier\thinkphp\thinkphp.php(97): think\think::start()
#11 d:\wamp64\www\aier\index.php(24): require('d:\\wamp64\\www\\a...')
#12 {main}
本来在另外一台电脑上wamp2.4 win7 完全可以运行,现在换了台电脑,wamp3.0 win10 就不能运行了,为什么啊?是不是配置没配好
回复讨论(解决方案) 这根本就是win10的问题。我换了win7马上能用了
如果报 404,那就是配置问题了
但你接下来的错误信息又是哪里来的呢?
table 'aier.u' doesn't exist [ sql语句 ] : replace into `u` () values ()
表 aier.u 不存在,就是你自己的问题了
知道问题了
控制器里:
如果直接用$user->add会直接操作数据库,不连model,比如我把控制器的$user->add改成$user->dadd,报 think\model:dadd方法不存在!
$user=d('user');
$id=$user->dadd(i('post.name'),i('post.phone'),i('post.id_card'),i('post.health_card'),i('post.hospitalized'),i('post.address'),i('post.contact_name'),i('post.contact_phone'));
请问这该怎么办?我的tp版本是3.2.3