【问题标题】:SQL Statement Not Returning AnythingSQL 语句不返回任何内容
【发布时间】:2012-02-24 23:35:34
【问题描述】:

我有一个表格,要求用户在继续操作之前回答他们自己的安全问题。我的表格如下:

    <form action="securitychecked.php" method="post">

<table width="70%" border="0">
  <tr>
    <td><?php $result = mysql_query("SELECT secret_question FROM public WHERE active = 'activated' AND ni = '". $_SESSION['ni']."'")
or die(mysql_error()); 

if (mysql_num_rows($result) == 0) {
       echo '<hr><h4>This Person Has Not Setup A Security Question</h4><hr> ';
    } else {

while($info = mysql_fetch_array($result))
{

        echo  $info['secret_question'];

}
    }?></td>
    <td><span id="sprytextfield1">
      <input type="text" name="secret_answer" id="secret_answer" />
      <span class="textfieldRequiredMsg">*</span></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><br /><input name="" type="submit" value="Continue" /></td>
  </tr>
</table>
</form>

我的 php 代码如下所示:

    <?php

$secret_anwser=$_POST['secret_anwser'];

$secret_anwser = stripslashes($secret_anwser);
$secret_anwser = mysql_real_escape_string($secret_anwser);

$sql="SELECT secret_anwser FROM public WHERE secret_anwser ='$secret_anwser' AND active = 'activated' AND ni = '". $_SESSION['ni']."'";

$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);


if($count==1){
header("location:votenow.php");
}

?>

我有一个名为 public 的表和一个名为 'secret_anwser' 的字段,但即使输入了正确的值,我也会继续得到一个空白页。谁能帮帮我?

谢谢

【问题讨论】:

标签: php mysql mysql-error-1064 mysql-management


【解决方案1】:

我猜你 PHP 中的所有 secret_anwser 都是拼写错误。

至少字段名称是 secret_answer 但您尝试获取 $_POST['secret_anwser']; ,您将永远无法在数据库中找到任何内容。

数据库和表的名称也可能是错误的。

【讨论】:

    最近更新 更多