0

I make a register code email, user, pass and when I click in "zr" insert this info in database, but I'm getting following error:

MySQL error: Column count doesn’t match value count at row 1

Code:

include ('config.php');
include('login_css.php');
$error = "";
if (isset($_POST['zr'])){
$date = date("m d Y");
$user_name = strip_tags($_POST['user']);
$user_pass = strip_tags($_POST['pass']);
$user_email = strip_tags($_POST['email']);
$empty = strip_tags($_POST['none']);
$empty.= strip_tags($_POST['none']);
$empty.= strip_tags($_POST['none']);
$day = strip_tags($_POST['day']);
$month = strip_tags($_POST['month']);
$year = strip_tags($_POST['year']);
$dob = "$day/$month/$year";

 if ($user_name == "") {
  $error = "Firstname cannot be left empty.";
    echo $error;
 }
 else if ($user_pass == "") {
  $error = "Lastname cannot be left empty.";
    echo $error;
 }
 else if ($user_email == "") {
  $error = "Email cannot be left empty.";
    echo $error;
 }

 //Check the username doesn't already exist
 $check_username = mysql_query("SELECT yser FROM users WHERE username='$user_name'");
 $numrows_username = mysql_num_rows($check_username);
 if ($numrows_username != 0) {
  $error = 'That username has already been registered.';
  echo $error;
 }
 else
 {
  $check_email = mysql_query("SELECT email FROM users WHERE email='$user_email'");
 $numrows_email = mysql_num_rows($check_email);
 if ($numrows_email != 0) {
  $error = 'That email has already been registered.';
  echo $error;
 }
 else
 {
 //Register the user
 $register = mysql_query("INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')") or die(mysql_error());
 die('Registered successfully!');
 }
 }
 }

?>

<!-- Form Mixin-->
<!-- Input Mixin-->
<!-- Button Mixin-->
<!-- Pen Title-->
<div class="pen-title">
<title>WebooHub - Join</title>
  <h1>WebooHub - Join</h1>
</div>
<!-- Form Module-->
<div class="module form-module">
  <div class="toggle"><i class="fa fa-times fa-pencil"></i>
  </div>
  <div class="form">
    <h2>Create Your Account</h2>
    <form action="u_register" method="POST">



      <button>Join Now</button>
    </form>
  </div>
  <div class="cta"><a href="login.php">Login?</a></div>
</div><strong></strong>
8
  • 5
    @FakhruddinUjjainwala I noticed lately you post an answer and a comment. The OP will see your answer, there's no need to comment. Commented Mar 1, 2016 at 15:23
  • same error : @FakhruddinUjjainwala Ujjainwala Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\Weboo\WeboHub\app\join\u_register.php on line 33 Column count doesn't match value count at row 1 Commented Mar 1, 2016 at 15:25
  • Your script is at risk for SQL Injection Attacks. Commented Mar 1, 2016 at 15:26
  • 1
    Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. Commented Mar 1, 2016 at 15:26
  • Please use PHP's built-in functions to handle password security. If you're using a PHP version less than 5.5 you can use the password_hash() compatibility pack. Commented Mar 1, 2016 at 15:26

2 Answers 2

4

The error message is telling you exactly what's wrong. Look at your INSERT statement:

INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')

You specify 3 columns, but provide 5 values.

Either provide only the 3 values you want to insert:

INSERT INTO users(user,pass,email) VALUES('$user_name','$user_pass','$user_email')

Or specify the 5 columns for which you're inserting values:

INSERT INTO users(someColumn,user,pass,email,someOtherColumn) VALUES('','$user_name','$user_pass','$user_email','$date')

Also, and this is important, your code is wide open to SQL injection. What this means is that you're blindly executing any code that your users send you in your database queries. Please take a look at this, as well as this. Use query parameters in prepared statements so that you treat user input as values instead of as code.


Additionally, you are storing user passwords in plain text. This is grossly irresponsible password handling. Please hash user passwords correctly. User passwords should be obscured behind a 1-way hash and should never be retrievable, not even by you as the system owner.

Sign up to request clarification or add additional context in comments.

Comments

0

Check out columns vs values:

You have 3 columns and 5 values. Those needs to be equal.

$register = mysql_query("INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')") or die(mysql_error());
 die('Registered successfully!');

Also strongly recommend using mysqli

2 Comments

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\Weboo\WeboHub\app\join\u_register.php on line 33 Column count doesn't match value count at row 1
@MeralAhmed Thats a select query error. Column count doesn't match value count at row 1 the above answer will resolve this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.