PHP/MYSQL - Error Array ( ) string(47) "Column count doesn't match value count at row 1" -
if (!$errors) { $salt = time(); $pwd = sha1($password . $salt); $mysqli = new mysqli('localhost','user','password','database'); if (mysqli_connect_errno()) { printf("connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $mysqli->prepare("insert users values (?,?,?,?,?,?)"); $stmt->bind_param('ssssss',$username,$pwd,$lastloggedin,$role,$paswordchangedate,$salt);
this code snippet, have counted, countless times (on fingers too..)- connection works, did var_dump($mysqli->error) error. when logging mysql , describing table 7 rows
field type null key default id int(11) no pri null auto_increment username varchar(50) yes uni null password varchar(50) yes null lastloggedin datetime yes null role varchar(20) yes null paswwordchangedate datetime yes null salt int(11) yes null
change query this:
$stmt = $mysqli->prepare("insert users values (null,?,?,?,?,?,?)"); $stmt->bind_param('ssssss',$username,$pwd,$lastloggedin,$role,$paswordchangedate,$salt);
note added first value null
autoincrement, missing id field.
remember when don't specify field name have make sure every field included.
this should work too:
$query = "insert users (username,password,lastloggedin,role,paswwordchangedate,salt) values (?,?,?,?,?,?) ;";
Comments
Post a Comment