2016-04-18 22 views
0
require_once('appvars.php'); 
require_once('connectvars.php'); 

// Connect to the database 
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) 
or die('Error connecting to MySQL server.'); 

if (isset($_POST['submit'])) { //check for submit 
// Grab the profile data from the POST 
$username = mysqli_real_escape_string($dbc, trim($_POST['username'])); 

$password1 = mysqli_real_escape_string($dbc, trim($_POST['pass1'])); 
$password2 = mysqli_real_escape_string($dbc, trim($_POST['pass2'])); // validate user input 
if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) { 
    // Make sure someone isn't already registered using this username 
    $query = "SELECT * FROM users WHERE username = '$username'"; 
    $data = mysqli_query($dbc, $query) 
    or die('Error querying database.'); 
    if (mysqli_num_rows($data) == 0) { // new function num_row gives you the number of rows retrieved from the query. 
    // The username is unique, so insert the data into the database 
( --> problem line) $query = "INSERT INTO users (username,pass) VALUES ('$username', SHA1('$pass1'), NOW())"; // SHA1 is encrytion being implied to password. 
    mysqli_query($dbc, $query); 

    // Confirm success with the user 
    echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>'; 

    mysqli_close($dbc); 
    exit();// is a function to get out of the program. 
    } 
    else { 
    // An account already exists for this username, so display an error message 
    echo '<p class="error">An account already exists for this username. Please use a different address.</p>'; 
    $username = ""; 
    } 
} //end of validation, user passed the validation. 
else { 
    echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>'; 
} 
} // end of submit 

mysqli_close($dbc); 

私はこれが頼まれていることは知っていますが、私は答えを見つけることができません。 SQLエラーが発生しました 数値1136 - 列数がクエリの値と一致しません: INSERT INTOユーザー(ユーザー名、パス)VALUES( '$ username'、SHA1( '$ pass1')、NOW())#1136 - 列数が値の数と一致しません。

1136 - 列数が値の数と一致しません。すべての値がリストされているようです。誰かが

は、あなたがあなたがこのようなあなたのINSERTクエリをerror.change与えている理由です、2列に3つの値を渡そうとしているあなたに

+1

ユーザーテーブルに追加しようとしている値の数は3ですが、2つの列名しか指定していないことがわかります。最後の値(NOW())に対応する他の列名を追加します。これはあなたの問題を解決します。 –

答えて

1

ありがとう私を助けてくださいすることができます。

$sql=INSERT INTO users (username,pass,date) VALUES ('$username', SHA1('$pass1'), NOW()); 
+0

日付変数はどこから来ますか? –

+0

日付を保存しているかどうか。あなたが今使用していた場合は、dateとnow.theクエリを完全に正常に動作します。 –

関連する問題