Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

php - #1136 - Column count doesn't match value count?

 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);

I know this has been asked alot but I can't find an answer. I am getting the SQL error number 1136 - Column count doesn't match value count on my query: INSERT INTO users (username,pass) VALUES ('$username', SHA1('$pass1'), NOW())

number 1136 - Column count doesn't match value count as you can see it seems all values are listed. Can someone please help me

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you are trying to pass three value in two column,that's why it is giving you error.change your insert query like this.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...