- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
/* Создание базы данных */
CREATE DATABASE userlistdb;
/* Создание таблицы */
CREATE TABLE `usertbl` (
`id` int(11) NOT NULL auto_increment,
`full_name` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`email` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`username` varchar(20) collate utf8_unicode_ci NOT NULL default '',
`password` varchar(32) collate utf8_unicode_ci NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
<?php
require("constants.php");
$connection = mysqli_connect('127.0.0.1', 'root', '', 'userlistdb');
if( $connection == false)
{
echo 'Не удалось подключиться к базе данных!<br>';
echo mysqli_connect_error();
exit();
}
?>
if(isset($_POST["register"])){
if(!empty($_POST['full_name']) && !empty($_POST['email']) && !empty($_POST['username']) && !empty($_POST['password'])) {
$full_name=$_POST['full_name'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$query = mysql_query ($connection, "SELECT `username` FROM `usertbl` WHERE `username` ='".$username."'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO usertbl
(full_name, email, username, password)
VALUES('$full_name','$email', '$username', '$password')";
$result=mysql_query($sql);
if($result){
$message = "Account Successfully Created";
} else {
$message = "Failed to insert data information!";
}
} else {
$message = "That username already exists! Please try another one!";
}
} else {
$message = "All fields are required!";
}
}
?>
<?php if (!empty($message)) {echo "<p class=\"error\">" . "MESSAGE: ". $message . "</p>";} ?>
<div class="container mregister">
<div id="login">
<h1>REGISTER</h1>
<form name="registerform" id="registerform" action="register.php" method="post">
<p>
<label for="user_pass">Username<br />
<input type="text" name="username" id="username" class="input" value="" size="20" /></label>
</p>
<p>
<label for="user_pass">Password<br />
<input type="password" name="password" id="password" class="input" value="" size="32" /></label>
</p>
<p class="submit">
<input type="submit" name="register" id="register" class="button" value="Register" />
</p>
<p class="regtext">Already have an account? <a href="login.php" >Login Here</a>!</p>
</form>