如何在PHP中的select查询中保留变量中的值

时间:2014-03-22 16:54:48

标签: php sql

我想要做的是检查Employee表中的密码,其中用户名填写在表单中..但我不知道该怎么做 错误显示:

  

注意:使用未定义的常量密码 - 假设'密码'在   第17行的E:\ Xamp \ htdocs \ login.php

错误的密码或用户名......

这是员工表

create table Employee(
E_ID number(10) primary key,
E_First_Name varchar2(10),
E_Last_Name varchar2(10),
user_name  varchar2(10) unique,
password varchar2(10),
E_Gender varchar2(6),
E_address varchar2(50),
E_phone_No number(11),
E_category varchar2(10),
EMP_salary number(20),
work_hour varchar2(20),
Date_Of_Join date
);

<?php
                   $conn=oci_connect("system","123","localhost/orcl");
    ob_start();
    $current_file=$_SERVER['SCRIPT_NAME'];
    $massage= "";
                   settype($bar, "string");
    if(isset($_POST['user_name'])&&isset($_POST['password']))           
    {

        $user_name= $_POST['user_name'];
        $password = $_POST['password'];
        if(!empty($user_name)&&!empty($password))
        {
                                                                             $sql = "select password into $bar  from Employee where user_name='".$user_name."' ";
                $stid = oci_parse($conn,$sql);
                $r = @oci_execute($stid);
                if(password==$bar )
                {
                    echo 'login verified...<br>';
                }
                else
                {
                    echo 'wrong password or user name ...<br>';
                }

        }
        else
        {
            $massage = "please fill up your username and password correctly<br>";
        }
    }

?>
<html>
<head>
<title>Login</title>
<style>
body
{
background:orange;
}
</style>
<head>
<body>
fill username and password to log in<br><br>
<?php echo $massage;?>
<hr color="green">
<form action="<?php echo $current_file;?>" method="POST">

    user_name:<br> <input type="text" name ="user_name" ><br><br>
    password:<br> <input type="text" name="password" ><br><br>
    <input type ="submit" value="Log In"><br><br>
                   <a href="OrderTable.php">please check  your Order_ID</a><br><br>



</form>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

您忘了在密码

之前添加$
 if(password==$bar )   //<--------- In this line
                {
                    echo 'login verified...<br>';
                }
                else
                {

应该是

if($password==$bar ) 

旁注:

  • 为您的PHP开发获取一个好的IDE。 (Google for PHP IDE),因此您可以在编码时避免此类错误。
  • 尝试使用PHP代码enable error reporting

<强> EDIT :

<?php
$conn=oci_connect("system","123","localhost/orcl");
ob_start();
$current_file=$_SERVER['SCRIPT_NAME'];
$bar="";
if(isset($_POST['user_name'])&&isset($_POST['password']))
{

    $user_name= $_POST['user_name'];
    $password = $_POST['password'];
    if(!empty($user_name)&&!empty($password))
    {
        $sql = "select password from Employee where user_name='".$user_name."' ";

        $stid = oci_parse($conn,$sql);
        $r = oci_execute($stid);
        while (($row = oci_fetch_array($stid, OCI_BOTH)) != false) {
            $bar=$row['password'];
        }
        if($password==$bar)
        {
            echo 'login verified...<br>';
        }
        else
        {
            echo 'wrong password or user name ...<br>';
        }

    }
    else
    {
        $massage = "please fill up your username and password correctly<br>";
    }
}

?>
<html>
<head>
    <title>Login</title>
    <style>
        body
        {
            background:orange;
        }
    </style>
<head>
<body>
fill username and password to log in<br><br>
<?php echo $massage;?>
<hr color="green">
<form action="<?php echo $current_file;?>" method="POST">

    user_name:<br> <input type="text" name ="user_name" ><br><br>
    password:<br> <input type="text" name="password" ><br><br>
    <input type ="submit" value="Log In"><br><br>
    <a href="OrderTable.php">please check  your Order_ID</a><br><br>



</form>
</body>
</html>