Jump to content

MYSQL error: column count doesn't match vakue count at row


mark103
 Share

Recommended Posts

Hi guys,

 

I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this:

 

www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp

 

 

However i have got a error which i don't know how to fix it.

 

Error: Column count doesn't match value count at row 1

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'mydbusername');
    define('DB_PASSWORD', 'mydbpassword');
    define('DB_DATABASE', 'mydbname');

$errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {

die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {

die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
  $username = clean($_GET['user']);
    $password = clean($_GET['pass']);
    $adduser = clean($_GET['user1']);
    $email = clean($_GET['email']);
    $IP = clean($_GET['ip']);
    if($username == '') {
  $errmsg_arr[] = 'username is missing';
  $errflag = true;
    }
    if($password == '') {
  $errmsg_arr[] = 'PASSWORD is missing';
  $errflag = true;
    }
    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {
   $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')";

if (!mysql_query($sql,$link))
  {
  die('Error: ' . mysql_error());
  }
echo "The information have been updated.";
  }
?>

 

Here's the name of the columns i have got in my database:

 

username
email
IP

 

 

I have input the correct columns names, so I can't correct the problem I am getting.

 

Please can you help?

Link to comment
Share on other sites

one thing i notice is you don't need quotes for members...so it can be like this INSERT INTO members..But i don't think this one will rectify the error..this is what i can see..

 

Those aren't quotes, they're backticks, which are fine to use, and in some cases required, around table and field names in MySQL.

Link to comment
Share on other sites

Edit: LOL again.

 

I recommend that you echo $sql as part of your die() error handling so that you can see exactly what the query is. I don't think that is the code and/or the query that is failing.

 

@sooner, those aren't quotes. They are back-ticks (yes it matters what they are.)

Link to comment
Share on other sites

Here it's:

 

Error: Column count doesn't match value count at row 1

Query: INSERT INTO member (username, email, IP) VALUES('','','','')

 

 

And here's the update code:

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'mydbusername');
    define('DB_PASSWORD', 'mydbpassword');
    define('DB_DATABASE', 'mydbname');
       
$errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {

die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {

die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
  $username = clean($_GET['user']);
    $password = clean($_GET['pass']);
    $adduser = clean($_GET['adduser']);
    $email = clean($_GET['email']);
    $IP = clean($_GET['ip']);
    if($username == '') {
  $errmsg_arr[] = 'username is missing';
  $errflag = true;
    }
    if($password == '') {
  $errmsg_arr[] = 'PASSWORD is missing';
  $errflag = true;
    }
    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {

if(isset($_GET['adduser'])) {
    $insert[] = 'username = \'' . clean($_GET['adduser']) .'\'';    
   }
  if(isset($_GET['email'])) {
    $insert[] = 'email = \'' . clean($_GET['email']) . '\'';
   }
  if(isset($_GET['ip'])) {
    $insert[] = 'ip = \'' . clean($_GET['ip']) . '\'';
   }
   $names = implode(',',$insert);
   $sql="INSERT INTO members (username, email, ip)
        VALUES('','$_POST[adduser]','$_POST[email]','$_POST[ip]')";

if (!mysql_query($sql,$link))
  {
  die('<br>Error: ' . mysql_error() . "<br>Query: $sql" );
  }
echo "The information have been updated";
  }
}
?>

Link to comment
Share on other sites

Thanks for your help.

 

This time I get a different error.

 

Error: Column count doesn't match value count at row 1

Query: INSERT INTO user_banned_list (username, email, IP_domain) VALUES('','')

 

 

Here's the update code:

 

  $sql = "INSERT INTO members (username, email, ip)
          VALUES('','$_GET[names]')";

Link to comment
Share on other sites

Thanks for your help.

 

This time I get a different error.

 

Error: Column count doesn't match value count at row 1

Query: INSERT INTO user_banned_list (username, email, IP_domain) VALUES('','')

 

 

Here's the update code:

 

  $sql = "INSERT INTO members (username, email, ip)
          VALUES('','$_GET[names]')";

 

That isn't the code causing that error message.

Link to comment
Share on other sites

LOL, none of the code/errors posted together match.

 

mark103, you cannot (successfully) write code by randomly changing things. You must know what you are changing and why you are changing it (you don't even have a names parameter in the URL, so the $_GET[names] you used in the last code you posted doesn't even exist) and you must read what the error messages are telling you.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.