Finally the connection was successful.
phpcn_u111636
phpcn_u111636 2018-02-08 21:21:12
0
0
1454

<?php

// Use the trim function to remove the redundant characters at the front and rear of the password and copy the password to determine whether the passwords entered twice are consistent.

if(trim($_POST['password']) != trim($_POST['repassword'])){

exit('The two passwords are inconsistent, please return to the previous one page');

}

//Get the username

$username = trim($_POST['username']);

// The password is encrypted using MD5, and the password is invisible to the outside world.

$password = md5(trim($_POST['password']));

// Get the user registration time, which is a unix timestamp. Not visible internally.

$time = time();

//Get the user’s registered IP address:

$ip = $_SERVER['REMOTE_ADDR'];


// The first step: Connect to the database server, use the mysqli_connect function to connect to the database server,

// mysqli_connect('database host localhost', 'database server login name', 'Database server login password', 'Database name', 'Database server port defaults to 3306');

// mysqli_connect('localhost', 'root','root', 'mylove', '3306');

$conn = mysqli_connect('localhost', 'root', 'root', 'mylove', '3306');

// Step 2: Judgment Error, mysqli_errno returns the connection error number, and returns 0 if there is no error.

//mysqli_error returns the connection error string. Print out all errors.

if(mysqli_errno($conn)){

echo mysqli_error($conn);

exit;

}

/ / Step 3: Select the database

mysqli_select_db($conn, 'mylove');

// Step 4: Set the database character set

mysqli_set_charset($conn, 'utf8');

// Step 5: Prepare SQL statements and combine SQL statements.

$sql = "insert into user(username ,password ,createtime,createip) values ​​('$username', '$password', '$time', '$ip')";

//Step 6: Send the SQL statement and send the sql statement prepared above to the mysql server. The mysql server will execute the sql statement sent.

$result = mysqli_query($conn, $sql);

//Step 7: Determine whether sending the SQL statement is successful, return true if successful, otherwise return false.

if($result){

echo 'Registration successful';

}else{

echo 'Registration failed';

}

echo 'The ID inserted by the current user is' . mysqli_insert_id($conn);

// Step 8: Close the database

mysqli_close($conn);


/*

Method to connect data:

1. First create a database on the database server.

2. Create a data table in this database.

3. Create a connection page to connect to the database.

4. Create a form page.

Summary: Collect data through forms, and then write the collected data into the database through the data processing page.

*/


?>


phpcn_u111636
phpcn_u111636

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template