This question is a bit strange? It seems that the time and IP cannot be obtained
$邂♥逅♥愛♥~
$邂♥逅♥愛♥~ 2018-02-05 22:32:15
0
6
1548

/*$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


##$sql = "insert into kui3(username,password,createtime ,createip) values('" . $username . "','" . $password . "','" . $time . "','" . $ip . "')";

Use The code in the course, that is, the code above, always fails to write. I don’t know what the problem is?

$邂♥逅♥愛♥~
$邂♥逅♥愛♥~

reply all(6)
寻觅 beyond

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

寻觅 beyond

`createtime` int(80) DEFAULT NULL, isn’t this int(80) a bit scary? And you can use the date type of the database

卿立平

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?

猪哥

String concatenation of SQL statements is incorrect

$邂♥逅♥愛♥~

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:

##<?php

if (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 number

if (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


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template