-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
33 lines (29 loc) · 856 Bytes
/
data.php
File metadata and controls
33 lines (29 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$mysql_servername = "localhost";
$mysql_username = "root";
$mysql_password = "love12.31";
$mysql_dbname = "myDB";
//connection
$conn = mysqli_connect($mysql_servername, $mysql_username, $mysql_password, $mysql_dbname);
//detect connection
if($conn->connect_error){
die("connect error: ".$conn->connect_error);
}
//check repeat username
$sql = "SELECT username FROM user WHERE username='".$username."'";
$result = $conn->query($sql);
if($result->num_rows>0){
$err_username = "error: username already exists";
}else{
//insert data
$sql = "INSERT INTO user(username, password) VALUES('".$username."','".$password."')";
if($conn->query($sql)===TRUE){
header("location:/login.php");
exit;
}else{
echo "data insert error".$conn->error;
}
}
//close connection
$conn->close();
?>