This is my snippet of PHP I am currently using to put a randomly generator string in a row, but it is not working. I need $actc to go into the actc field of the row, but it is not actually doing that, it stays 0.
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$actc = '' ;
while ($i <= 11) {
$num = rand() % 33;
$tmpc = substr($chars, $num, 1);
$actc = $actc . $tmpc;
$i++;
}
mysql_query("INSERT INTO users (username, pass, email, ip, actc)
VALUES ('".$nl."', '".$pw."', '".$email."', '".$_SERVER['REMOTE_ADDR']."', '".$actc."')") or die(mysql_error());
My table structure exported in SQL:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(255) NOT NULL,
`pass` varchar(60) NOT NULL,
`email` varchar(255) NOT NULL,
`ip` varchar(20) NOT NULL,
`actc` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4531 ;
It looks like you’re initializing $actc as a string, but the column type in mysql is an int. You can’t insert a non-Int into an Int column.
Also you are quoting $actc as thought it were a string in your insert statement. Ints are not quoted in mysql insert statements.