PHP在简单的选择查询上抛出错误?

时间:2012-09-24 22:15:16

标签: php forms oracle11g oci

不确定发生了什么,我不断收到错误。我已将问题减少到相当小的测试用例,见下文:


的login.html

<form action="login.php" method="post">
    <input type="email" name="email" required />
    <input type="password" name="password" required />

    <input type="submit" value="Login"/>
</form>

的login.php

$email    = $_POST["email"];
$password = sha1($_POST["password"]);

$stid2 = oci_parse($conn, 'SELECT EMAIL, PASSWORD FROM TUSERS where EMAIL =: email AND PASSWORD =: password');
oci_execute($stid2);

$nrows = oci_fetch($stid2);

print var_dump($nrows);

错误

  

警告:oci_execute():ORA-01008:并非所有变量都绑定在第5行的login.php中

     

警告:oci_fetch():ORA-24374:在获取或执行之前定义未完成,并在第7行的login.php中获取bool(false)

2 个答案:

答案 0 :(得分:1)

您需要将变量$ email和$ password绑定到oracle占位符。见oci_bind_by_name。此外,占位符应为​​:email:password。冒号(:)和占位符名称(emailpassword)之间有空格。

答案 1 :(得分:1)

您在查询中添加了变量占位符,但没有将任何内容绑定到它们

$stid2 = oci_parse($conn, 'SELECT EMAIL, PASSWORD FROM TUSERS where EMAIL =:email AND PASSWORD =:password');
oci_bind_by_name($stid2, ':email', $email);
oci_bind_by_name($stid2, ':password', $password);
oci_execute($stid2);

请参阅oci_bind_by_name