所以我一直在尝试创建注册页面,但每当我尝试注册用户时,它都会失败。
这是PHP页面:
<?php
require 'databaseconnect.php';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO Technichians (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', $_POST['password']);
if( $stmt->execute() ):
die('success');
else:
die('fail');
endif;
endif;
?>
<html>
<head>
<!-- TypeKit Fonts -->
<!-- JQuery JS -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- CSS Files -->
<link rel = "stylesheet" href="CSS/CSS_Main.css" type = "text/css">
<link rel = "stylesheet" href="CSS/CSS_Index.css" type = "text/css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<!-- TypeKit Fonts -->
<script src="//use.typekit.net/umi3ujh.js"></script>
<script>try{Typekit.load();}catch(e){}</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SWAT Technician Registration</title>
<link rel="ICON" href="CSS/images/favicon.ico" type="image/ico" />
</head>
<body>
<div class = "container_main">
<a name="top"></a>
<div class = "containerDEF">
<center><img class = "fixed loginImg" src = "CSS/images/SWAT_logo.png" alt = "DesignLogo" width = "300" height="300px"></center>
<form action = "registerswat.php" method = "POST">
<div class="input-group inputLogIn" id = "UsernameInput">
<span class="input-group-addon" id="basic-addon1">Username:</span>
<input type="text" class="form-control" placeholder="ex. mPond" aria-describedby="basic-addon1" name = "username">
</div>
<div class="input-group inputLogIn" id = "UsernameInput">
<span class="input-group-addon" id="basic-addon1">Registration Pin:</span>
<input type="password" class="form-control" placeholder="******" aria-describedby="basic-addon1" name = "pin">
</div>
<div class="input-group inputLogin" id = "PasswordInput">
<span class="input-group-addon" id="basic-addon1">Password:</span>
<input type="password" class="form-control" placeholder="ex. HelloSweetie" aria-describedby="basic-addon1" name = "password">
</div>
<div class="input-group inputLogin" id = "PasswordInput">
<span class="input-group-addon" id="basic-addon1"> Confrim Password:</span>
<input type="password" class="form-control" placeholder="ex. HelloSweetie" aria-describedby="basic-addon1" name = "confirmPassword">
</div>
<div class="input-group inputLogin" id = "PreferredName">
<span class="input-group-addon" id="basic-addon1"> Preferred Name:</span>
<input type="text" class="form-control" placeholder="ex. River" aria-describedby="basic-addon1" name = "preferredName">
</div>
<center><input type = "submit" class = " submitButton" name = "Login" value = "Register"></center>
</form>
<center><p>Didn't mean to be here? Go <a href = "index.html">Back</a>.</p>
<p>Just want to login? <a href = "swatlogin.php">Login Here</a>. </p>
</center>
</div>
<div class = "Footer bottom">
<p>SWAT Team 2016</p>
<a class ="link" href = "contact.html">Contact</a>
</div>
</div>
<script src = "Scripts/Script_Main.js"></script>
</body>
</html>
这是必需的databaseconnect.php:
<?php
$server = 'localhost';
$username = 'SWATAdmin';
$password = 'SWAT2016DBAccess';
$database = 'SWATDatabase';
try{
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
die("Connection failed: " . $e->getMessage());
}
?>
我真的不知道出了什么问题。我在if语句中构建了它是否失败或成功,并且它继续失败并且用户名不会在数据库中结束。任何帮助将不胜感激!