Home > Backend Development > PHP Tutorial > 如何判断用户名和密码为空就不执行下面的SQL语句

如何判断用户名和密码为空就不执行下面的SQL语句

WBOY
Release: 2016-06-13 12:45:04
Original
1163 people have browsed it

怎么判断用户名和密码为空就不执行下面的SQL语句
初学着请教,目的就是判断表单过来的数据,如果为空就提示输入用户和密码,并且不执行下来的SQL,如果表单里面的数据有值就执行下面的SQL语句,这里先不判断表单的数据是否合法之类的。

<br />
<br />
$user=$_POST[name];  //获取表单的name<br />
$pwd=$_POST[passwd];  //获取表单的passwd<br />
<br />
if($user==''&&$pwd==''){    //这个地方我不知道可不可以这样来判断,如果USER等于空,就提示输入密码<br />
   echo '请输入用户和密码';   <br />
}else{                   //如果上面两个不为空,就执行下面的SQL语句并且插入到数据库。<br />
  $sql="insert into ('$user','$pwd')";<br />
  mysql_query($sql);<br />
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template