0

次のコードに問題があります。

$sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES
    ('$hash', '$lastname', '$email', '$email')";

  mysqli_query($MyConnection, $sql);

  if(!mysqli_query($MyConnection, $sql)) {
    echo 'We are sorry, there are some problems with saving your data. Please try again within a few minutes.';
  }
  else {
    echo 'We have succesfully saved your data. An activation e-mail will now be send to the e-mail address that you
      have provided us.';
  }

関数の入力ミスや誤用による直接的なエラーは発生しません。ただし、失敗した場合のifステートメントのメッセージ、「申し訳ありません(..)」というテキストが表示されます。

mysqli_query($MyConnection, $sql) 関数の実行に問題があるはずです。しかし、私はそれがどこにあるのかわかりません。

PS 評判が 10 を下回っているため、画像を投稿できません (その点に制限するのは非常に奇妙です)。

あなたの何人かがほとんど/すべてのコードを提供しているように:

<?php

  // Opens the connection of the MySQL Database
  $MyConnection = mysqli_connect('fdb6.biz.nf', '1446018_amp', '-') 
         or die("Could not connect to the database, please try again");
  mysqli_select_db($MyConnection,'Users');

  mysqli_connect_errno();

  // Website Url:
  $website = 'http://www.askmephilosophy.co.nf/';

  // Information provided by the user
  $username = $_POST['username'];
  $password = $_POST['password'];   // Will get encrypted.
  $lastname = $_POST['lastname'];
  $email = $_POST['email'];

  // A higher "cost" is more secure but consumes more processing power
  $cost = 5;

  // Create a random salt
  $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');

  // Prefix information about the hash so PHP knows how to verify it later.
  // "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
  $salt = sprintf("$2a$%02d$", $cost) . $salt;

  // Hash the password with the salt
  $hash = crypt($password, $salt);

  $sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES
    ('$hash', '$lastname', '$email', '$email')";

  mysqli_query($MyConnection, $sql);
  var_dump(mysqli_error($MyConnection));

  if(mysqli_query($MyConnection, $sql)) {
    echo 'We have succesfully saved your data. An activation e-mail will now be send to the e-mail address that you
      have provided us.';
  }
  else {
    echo 'We are sorry, there are some problems with saving your data. Please try again within a few minutes.';
    mysqli_error($MyConnection);
  }

  mysqli_close($MyConnection);

?>
4

4 に答える 4

0

値が 3 つしかないのはなぜですか。挿入しようとしている項目の数 (4) と一致しません ...

 $sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES
('$username', '$hash', '$lastname', '$email')";

編集:

多分こう書くと思います

 $sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES
    ({$username}, {$hash}, {$lastname}, {$email})";

編集: パスワードを「-」にすることはできません

次のように接続情報を更新します。

$db = new mysqli('fdb6.biz.nf', 'user', 'pass', 'Users');

if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}

もう一度編集:

    $myConnection = new mysqli('fdb6.biz.nf', 'user', 'pass', '1446018_amp');
    $myConnection->mysqli_select_db($MyConnection,'Users'); 
于 2013-08-21T19:03:07.583 に答える
0

まず、 のインスタンスが 2 つあるため、そのレコードを 2 回挿入していますmysqli_query($MyConnection, $sql);。最初のものだけを削除できます。

ここでの問題は、4 つのフィールドに 3 つの値を挿入していることです。

とにかく、特定のエラーを取得できます

mysqli_error($MyConnection);

エコーの最後に追加するかvar_dump(mysqli_error($MyConnection));、新しい行に追加します。

于 2013-08-21T19:06:02.117 に答える