0

我在使用以下代码时遇到问题:

# 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>
          ';

每当我尝试注册一个新帐户时,我都会被发送到一个由主机预设的错误页面。所以我得到一个404错误。我很确定问题出在

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

我在那段代码中做错了什么?

4

1 回答 1

1

404 错误来自未找到的文件

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

文件http://www.askmephilosophy.co.nf/contact.php不存在。

必须有一些其他文件在您未显示的代码的某些部分中不存在(在 elseif 之后的 else 中?)。如果用户名和电子邮件都是免费的,则可以调用。

由于大多数链接http://www.askmephilosophy.co.nf会导致 404 错误,因此您正在为自己制造麻烦。

所有链接都应该指向真实文件。在内容可用之前,这些存根文件应该有一条消息,如“建设中”和文件名等。

于 2013-11-16T23:21:31.930 回答