我使用pdo创建登录脚本但我有一些问题
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>barr</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<modules>
<module>webapp</module>
<module>frontend</module>
</modules>
</project>
我认为如果结果问题我怎么修复?我想如果用户名=用户名和pw登录。
答案 0 :(得分:2)
改变这个:
$query = $db->prepare("SELECT * FROM user WHERE
username = :userg,
pw = :pwg");
$result = $query->execute(array(
'userg' => $_POST['userg'],
'pwg' => $_POST['pwg'],
));
对此:
$query = $db->prepare("SELECT * FROM user WHERE
username = :userg AND pw = :pwg");
$query->bindParam(':userg', $_POST['userg']);
$query->bindParam(':pwg', $_POST['pwg']);
$query->execute();
感谢Fred-ii-在select查询中捕获我的错误! 变化:
if($result > 0){
echo "ok";
}else{
echo "no";
}
致:
$count = $query->rowCount();
if($count==1){
echo "ok";
}else{
echo "no";
}
答案 1 :(得分:0)
尝试此查询[SELECT * FROM user WHERE username =:user AND pw =:pw]
if($_POST['giris']){
$req = $bdd->prepare('SELECT * FROM user WHERE username = :user AND pw = :pw');
$req->execute(array('user' => $_POST['userg'], 'pw' => $_POST['pwg'] ));
if($result > 0){
echo "ok";
}else{
echo "no";
}
}
&#13;