如何在php中使用select命令 [英] how use select command in php
本文介绍了如何在php中使用select命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我是新的在 php中。下面的代码工作正常。但如果我更改选择命令赞 this :
$ sql = SELECT login_id,密码FROM user_right WHERE login_id =& $ username& and password = $ password'
它显示错误记录未找到。另外我需要显示选择用户的角色。请帮助我
<?php
include_once ' ../ inc / header.php';
if (isset($ _ POST [' submit'])&& $ _POST [' submit']!= )
{
if(empty($) _POST [' username']))
{
$ handleError = 用户为空!;
$ _SESSION [ errormsg] = $的HandleError 跨度>;
header( 位置:../ notification / errormsg.php);
// echo $ handleError;
返回 false;
}
if(空($ _ POST [' password']))
{
$ handleError = 密码为空!;
$ _SESSION [ errormsg] = $的HandleError 跨度>;
header( 位置:../ notification / errormsg.php);
// echo $ handleError;
返回 false;
}
$ username = trim($ _ POST [' 用户名跨度>]);
$ password = trim($ _ POST [' 密码跨度>]);
尝试
{
$ sql = SELECT * FROM user_right WHERE login_id ='$ username'和password ='$ password';
$ stmt = $ dbh-> prepare($ sql);
$ stmt-> setFetchMode(PDO :: FETCH_ASSOC);
if ($ stmt = $ dbh-> query($ sql)){
if ($ stmt-> fetchColumn()> 0)
{
$ _SESSION [ username] = $ username ;
$ _SESSION [ password] = $密码跨度>;
header( 位置:../ admin /);
exit();
}
else
{
$ handleError = 用户名或密码错误;
$ _SESSION [ errormsg] = $的HandleError 跨度>;
header( 位置:../ notification / errormsg.php);
exit();
};
}
}
catch (PDOException $ e)
{
echo $ e-> getMessage()。 \ n;
file_put_contents(' PDOErrors.txt',$ e-> getMessage(),FILE_APPEND );
}
}
包括' ../ inc / footer.php';
解决方案
sql = < span class =code-string> SELECT login_id,password FROM user_right WHERE login_id =&
username& and password =
password'
它显示错误记录未找到。我还需要显示选择用户的角色。请帮助我
<?php
include_once ' ../inc / header.php';
if (isset(
Hi
I am new in php. Below code works fine. But If I change Select Command Like this:
$sql = "SELECT login_id,password FROM user_right WHERE login_id = &$username& and password = $password'
It shows error recorde not found. Also I need to show the role of select user. Pls Help me
<?php
include_once'../inc/header.php';
if (isset($_POST['submit']) && $_POST['submit'] != "" )
{
if(empty($_POST['username']))
{
$handleError = "User is empty!";
$_SESSION["errormsg"] = $handleError;
header("Location:../notification/errormsg.php");
//echo $handleError;
return false;
}
if(empty($_POST['password']))
{
$handleError = "Password is empty!";
$_SESSION["errormsg"] = $handleError;
header("Location:../notification/errormsg.php");
//echo $handleError;
return false;
}
$username = trim($_POST['username']);
$password = trim($_POST['password']);
try
{
$sql = "SELECT * FROM user_right WHERE login_id = '$username' and password = '$password'";
$stmt = $dbh->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
if ($stmt = $dbh->query($sql)) {
if ($stmt->fetchColumn() > 0)
{
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
header("Location:../admin/");
exit();
}
else
{
$handleError="user name or password is wrong";
$_SESSION["errormsg"] = $handleError;
header("Location:../notification/errormsg.php");
exit();
};
}
}
catch (PDOException $e)
{
echo $e->getMessage() . "\n";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
}
include '../inc/footer.php';
解决方案
sql = "SELECT login_id,password FROM user_right WHERE login_id = &
username& and password =
password' It shows error recorde not found. Also I need to show the role of select user. Pls Help me
<?php include_once'../inc/header.php'; if (isset(
这篇关于如何在php中使用select命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文