我有一個現有的登錄/註冊系統,我想這樣做以便您在註冊時自動創建一個目錄用戶名,我已經把我原來的註冊腳本放在下面。我已經包括了整個寄存器文件中的代碼,所以你得原諒的混亂擁有現有的登錄/用戶系統,想知道如何在用戶註冊時創建文件夾
<?php include "../assets/database/160216.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
<title>Connect With Me</title>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="../../assets/css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="../../assets/css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
</head>
<body>
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="../../assets/js/materialize.js"></script>
<script src="../../assets/js/init.js"></script>
<header>
<!--Navigation Menu-->
<div class="navbar-fixed">
<nav class="white" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="../../index.html" class="brand-logo">Connect With Me</a>
<ul class="right hide-on-med-and-down">
<li><a href="../../index.html#about">About</a></li>
<li><a href="../../index.html#contact">Contact</a></li>
<li><a href="../login">Login</a></li>
</ul>
<ul id="nav-mobile" class="side-nav">
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="../login">Login</a></li>
</ul>
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
</div>
<!--Image Header With Text-->
<div id="index-banner" class="parallax-container">
<div class="section no-pad-bot">
<div class="container">
<br><br>
<br> <h1 class="header center teal-text text-lighten-2"><br>Register</h1>
<div class="row center">
<h5 class="header col s12 light">Register And Start Using Immediately.</h5>
</div>
<br><br>
</div>
</div>
<div class="parallax"><img src="../../assets/images/bg.jpg" alt="Unsplashed background img 1"></div>
</div>
</header>
<div id="main" class="center">
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$email = mysql_real_escape_string($_POST['email']);
$checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
if(mysql_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
}
else
{
$registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
if($registerquery)
{
echo "<h1>Success</h1>";
echo "<p>Your account was successfully created. Please <a href=\"../index.php\">click here to login</a>.</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
}
else
{
?>
<main>
<br>
<div class="container">
<div class="section">
<form method="post" action="index.php" name="registerform" id="registerform" class="col s12">
<div class="row">
<div class="input-field col s12">
<input type="text" name="username" id="username">
<label for="username">Username</label>
</div>
<div class="input-field col s12">
<input id="password" type="password" name="password" class="validate">
<label for="password">Password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="email" type="text" name="email" id="email" class="validate">
<label for="email">Email</label>
</div>
</div>
<button class="btn waves-effect waves-light center" type="submit" name="register" id="register">Register</button>
</form>
</div>
<?php
}
?>
</div>
</body>
</html>
非常感謝,我希望你們其中一個人有什麼建議/想法。
更新 - 感謝評論,這些都非常有幫助。
http://php.net/manual/en/function.mkdir.php。不要使用'mysql_'它已棄用並從PHP 7中刪除。使用'mysqli_'或'PDO'。 –
類似於'mkdir「$ BASE_DIR」.DIRECTORY_SEPARATOR。「$ username」'其中'$ BASE_DIR'是您希望創建文件夾的目錄。另外,使用綁定佔位符,您的代碼容易受到SQL注入攻擊 –
請從邏輯上分離你的標記。 –