我刚刚在关于制作社交网络的视频中找到了这段代码,而且我是php的新手。那么有人可以解释一下这段代码在做什么吗?另外,有人可以在网上建议一些好的免费php资源吗?
代码:(index.php)
<?php include ("./inc/header.inc.php");?>
<?php include("./inc/connect.inc.php");?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$con = mysqli_connect("localhost", "root", "password", "database_social");
date_default_timezone_set('UTC');
$reg = @$_POST['reg'];
$fn = @$_POST['first_name'];
$ln = @$_POST['last_name'];
$un = @$_POST['username'];
$em = @$_POST['email'];
$em2 = @$_POST['email2'];
$pswd = @$_POST['password'];
$pswd2 = @$_POST['password2'];
$d = date("Y-m-d"); // Year - Month - Day
if (isset($reg)) {
if ($em==$em2) {
$u_check = mysqli_query($con,"SELECT username FROM users WHERE username='$un'");
$check = mysqli_num_rows($u_check);
$e_check = mysqli_query($con,"SELECT email FROM users WHERE email='$em'");
$email_check = mysqli_num_rows($e_check);
if ($check == 0) {
if ($email_check == 0) {
if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) {
if ($pswd==$pswd2) {
if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysqli_query($con,"INSERT INTO 'database_social'. 'users' (id, username, first_name, last_name, email, password, sign_up_date, activated) VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0',)");
die("Login to your account to get started ...");
echo "inserted!";
}
}
}
else {
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Sorry, but it looks like someone has already used that email!";
}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
?>
<div style="width: 800px; margin: 0px auto 0px auto;">
<table id="SignUpTable">
<tr>
<td width="40%" valign="top">
<h2>Enter The World Today!</h2>
<form action="#" method="POST">
<input class="fname" type="text" name="first_name" size="25" placeholder="First Name"><br/> <br/>
<input class="lname" type="text" name="last_name" size="25" placeholder="Last Name"><br/><br/>
<input class="uname" type="text" name="username" size="25" placeholder="Username"><br/><br/>
<input class="email" type="text" name="email" size="25" placeholder="Email"><br/><br/>
<input class="email2" type="text" name="email2" size="25" placeholder="Re-enter Email"><br/><br/>
<input class="password" type="password" name="password" size="25" placeholder="Password"><br/><br/>
<input class="password2" type="password" name="password2" size="25" placeholder="Re-enter Password"><br/><br/>
<input class="buttonSignUp" type="submit" name="reg" value="Enter The World!">
</form>
</td>
</tr>
</table>
<?php include ("./inc/footer.inc.php");?>
谢谢!
答案 0 :(得分:0)
我可以推荐YouTuber TheNewBoston 。他有一些关于PHP的教程。他们中的大多数都很老了,但他解释了PHP,MySql,HTML,CSS等等。
但请记住,如果您有疑问,请查看PHP Documentation。