drsc10888 2013-11-16 21:23
浏览 60
已采纳

PHP SELECT * FROM无法正常工作

I am having trouble with the following code:

# Connection:
      require('config.php');
      $MyConnection = new PDO('mysql:host=x;dbname=x', $dbusername, $dbpassword);
      $MyConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      # Collecting:
      $username = htmlspecialchars($_POST['username']);
      $password = htmlspecialchars($_POST['password']);
      $lastname = htmlspecialchars($_POST['lastname']);
      $email = htmlspecialchars($_POST['email']);

      # Checking:
      $findUser = $MyConnection->prepare("SELECT * FROM Users WHERE 
        Username = :username OR Email = :email LIMIT 2");
      $findUser->bindParam(':username', $username);
      $findUser->bindParam(':email', $email);
      $findUser->execute();
      $foundUser = $findUser->fetch(PDO::FETCH_OBJ);

      if($foundUser->Username == $username) {
        echo '
          <div id="pop-up" class="error">
          This username is already in use. Please choose another one.
          </div>
          ';
      }
      elseif ($foundUser->Email == $email) {
        echo '
          <div id="pop-up" class="error">
          This email address is already in use. Please choose another one. <br />
          If you think this is impossible, please
          <a href="http://www.askmephilosophy.co.nf/contact.php">contact us</a>.
          </div>
          ';

Whenever I try to register a new account I get sent to an error page, pre-set by the host. So I get a 404 error. I'm very sure the problem lays in the

$findUser = $MyConnection->prepare("SELECT * FROM Users WHERE Username = :username OR Email = :email LIMIT 2");

What am I doing wrong in that bit of code?

  • 写回答

1条回答 默认 最新

  • douhu4091 2013-11-16 23:21
    关注

    The 404 error is from a file not found.

    Such as

    <a href="http://www.askmephilosophy.co.nf/contact.php">contact us</a>.
    

    File http://www.askmephilosophy.co.nf/contact.php does not exist.

    There must be some other file that does not exist in some part of the code you don't show (in the else after elseif ?) . Could be called if both Username and Email are free.

    As most of links in http://www.askmephilosophy.co.nf cause 404 error you are heaping up trouble for yourself.

    All links should be to real files. Until the content is available these Stub files should have a message like "Under Construction" and name of file etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记