/*$sql = "insert into kui3(username,password,createtime,createip)values('$username','$password',222,3333)";*/
Use the above code to change the underlined part, and you can successfully write
6 answers
Success code:
The table statement is as follows:
CREATE TABLE `kui3` (
`id` int(32) NOT NULL AUTO_INCREMENT ,
`username` varchar(30) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`createtime` int(80) DEFAULT NULL,
`createip` varchar(60) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 |
The complete code of the connect.php file is as follows:
##<?phpif (trim ($_POST['password']) != trim($_POST['repassword'])) { exit('The two passwords are inconsistent, please return to the previous page');}$username = trim($_POST['username']);$password = md5(trim($_POST['password']));$time = time();$ip = $_SERVER["REMOTE_ADDR"];$conn = mysqli_connect('localhost', 'root', 'root');//If there is an error, there is an error numberif (mysqli_errno($conn)) { echo mysqli_error($conn); exit; }mysqli_select_db($conn, 'kui');mysqli_set_charset($conn, 'utf8');$sql = "insert into kui3(username,password,createtime,createip) values('" . $username . "','" . $password . "','" . $time . "','" . $ip . "')" ;$result = mysqli_query($conn, $sql);if ($result) { echo 'Success';} else { echo 'Failed';}echo 'The ID inserted by the current user is' . mysqli_insert_id($conn);mysqli_close($ conn);?>CREATE TABLE IF NOT EXISTS user (
id int(11) NOT NULL,
username varchar(30) NOT NULL,
password char( 32) NOT NULL,
createtime int(11) NOT NULL,
createip int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
There are two questions here:
The first one should be, password varchar(32) not null;
The second and last createip type should be set to string,
The transfer is OK after modification
The ID inserted successfully by the current user is 13
Do we need to create a table in the database first? That is to say, the table statement must be executed first before the connection can be successful:
CREATE TABLE `kui3` (
`id` int(32) NOT NULL AUTO_INCREMENT,
`username` varchar(30) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`createtime` int(80) DEFAULT NULL,
`createip` varchar( 60) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 |
Yes?
`createtime` int(80) DEFAULT NULL, isn’t this int(80) a bit scary? And you can use the date type of the database
Then when inserting, enclose the time in quotation marks, because the time is stored in the form of a string, both $time and ip in your question should be enclosed in parentheses
Hot tools Tags
Hot Questions
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
20522
7
13634
4






