错误代码
<?php/** * Created by PhpStorm. * User: Administrator * Date: 2015/8/16 * Time: 15:37 */if(!isset($_POST['name'])){ die('user name not define');}if(!isset($_POST['password'])){ die('user name not define');}if(empty($_POST['name'])){ die('user name is empty');}if(empty($_POST['password'])){ die('user password is empty');}require_once 'connect_server.php';connectdb();$name=$_POST['name'];$password=$_POST['password'];$sql="select * from users WHERE name=$name AND password=$password";$result=mysql_query($sql);$new=mysql_fetch_assoc($result);if($new['name']==$name&&$new['password']==$password){ echo "<script>alert('登陆成功');window.location='zhuye.php'</script>";}else{ echo "<script>alert('登陆失败');window.location='zhuye.html'</script>";}
<?phprequire_once 'function.php'?><!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>所有用户</title></head><body><a href="adduser.html">添加用户</a><?php$conn=connectDb();mysql_select_db('test',$conn);$result=mysql_query("SELECT * FROM users",$conn);$dataCount=mysql_num_rows($result);echo"<table border='1'>";for($i=1;$i<$dataCount;$i++){ $result_arr=mysql_fetch_assoc($result); $id=$result_arr['id']; $name=$result_arr['name']; $age=$result_arr['age']; echo"<tr><td>$id</td><td>$name</td><td>$age</td><td><a href='edituser.php?id=$id>'>修改</a><br> <a href='deleteuser.php?id=$id>'>删除</a> </td></tr>";}echo"</table>";?></body></html>
"select * from users WHERE name=$name AND password=$password"
"select * from users WHERE 'name'=$name AND 'password'=$password"
$sql="select * from users WHERE name=$name AND password=$password";
改为:
$sql="select * from users WHERE name='".$name."' AND password='".$password."'";
因为你$name,$password如果为空,会造成语法错误。
还是错的?把sql语句再改成这样试试,应该是$name和$password没有被当成字符串导致出错。。。
"select * from users WHERE 'name'=".$name." AND 'password'=".$password
还是错的?把sql语句再改成这样试试,应该是$name和$password没有被当成字符串导致出错。。。
"select * from users WHERE 'name'=".$name." AND 'password'=".$password
"select * from users WHERE name='".$name."' AND password='".$password."'";
还是错的?把sql语句再改成这样试试,应该是$name和$password没有被当成字符串导致出错。。。
"select * from users WHERE 'name'=".$name." AND 'password'=".$password
"select * from users WHERE name='".$name."' AND password='".$password."'";
$sql="select * from users WHERE name=$name AND password=$password";
改为:
$sql="select * from users WHERE name='".$name."' AND password='".$password."'";
因为你$name,$password如果为空,会造成语法错误。
还是错的?把sql语句再改成这样试试,应该是$name和$password没有被当成字符串导致出错。。。
"select * from users WHERE 'name'=".$name." AND 'password'=".$password
"select * from users WHERE name='".$name."' AND password='".$password."'";
还是错的?把sql语句再改成这样试试,应该是$name和$password没有被当成字符串导致出错。。。
"select * from users WHERE 'name'=".$name." AND 'password'=".$password
"select * from users WHERE name='".$name."' AND password='".$password."'";
$sql="select * from users WHERE name=$name AND password=$password";
如果是数值型的$name和$password变量,可以在SQL语句中直接使用,如果是字符串类型的变量,需要加单引号
我把代码拆成三段,你应该能明白了。两个那个点是用来连接字符串的,意思是告诉PHP:点之后的变量是个字符串
"select * from users WHERE name='"
"' AND password='"
"'"
我把代码拆成三段,你应该能明白了。两个那个点是用来连接字符串的,意思是告诉PHP:点之后的变量是个字符串
"select * from users WHERE name='"
"' AND password='"
"'"