您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

#生手来袭# 一段简单的代码为什么提示出错

2025/6/15 3:46:29发布19次查看
#新手来袭# 一段简单的代码为什么提示出错
public function addemail(){
  $email_name=$_post['name'];
  $email_email=$_post['email'];
$con=mysqli_connect(localhost,root,root,bottlelover)
  or die('connect error');
mysqli_set_charset($con,utf8);
$sql=select * from email_list where email_email = $email_email;
  $result=mysqli_query($con,$sql)
  or die('query1 error');
if($row=mysqli_fetch_array($result)){
  $this->assign(res,'邮箱已被使用,用户添加失败');
  mysqli_close($con);
  $this->display(bottleloveradd);
  }
  else {
  $sql=insert into email_list(email_name,email_email) values ('$email_name','$email_email');
  $result=mysqli_query($con,$sql)
  or die('query2 error');
  $this->assign(res,'新用户添加成功');
  mysqli_close($con);
  $this->display(bottleloveradd);
  }
  }
--------------------------------------------以上是代码--------------------
我的本意是添加新用户之前要检查邮箱是不是已经被使用,
$sql=select * from email_list where email_email = $email_email;
  $result=mysqli_query($con,$sql)
  or die('query1 error');
这段代码提示query1 error错误,其他运行正常;为什么,明显没有错啊,表名没错,列名没错,变量名都没错.....
------解决方案--------------------
$sql=select * from email_list where email_email = '$email_email';
------解决方案--------------------
字符类型的量要用引号括起
正因为太简单了,所以容易忽视
------解决方案--------------------
楼上正解,少了单引号,因为这是字符串
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product