0
我有一個簡單的html表單,用於將POST字段中的信息發送到文件register.php。在register.php中,回聲成功執行只是爲了顯示文件已被輸入。下一行使用include_once來包含一個名爲UserManagement.php的文件,其中包含一個具有相同名稱的類。然後嘗試實例化此類,以便可以訪問它的方法,但程序流似乎永遠不會超過register.php中的第一個echo語句。 我希望有更有經驗的人會直接發現菜鳥的錯誤。我花了很長時間研究問題是什麼,我似乎無法得到它。php include_once讓我的代碼停止運行
我2個PHP文件和我的HTML表單低於:
<form action="register.php" method="POST">
Username: <input type="text" name="uname" /><br />
FirstName: <input type="text" name="fname" /><br />
Last Name: <input type="text" name="lname" /><br />
Date of Birth: <input type="date" name="dob" /><br />
Telephone: <input type="mob" name="tel" /><br />
Email: <input type="email" name="email1" /><br />
Confirm Email: <input type="email" name="email2" /><br />
Password: <input type="password" name="pass1" /><br />
Confirm Password: <input type="password" name ="pass2" /><br />
<input type="submit" value="Register" name="sub" />
<br/><A HREF="login.php">Already Registered? Login Here</A><br/>
</form>
register.php
<?php
echo "entered register.php";
require_once('UserManagement.php');
echo "userman was included";
$um = new UserManagement();
echo "usermanagement object created";
$response = array("error" => FALSE);
//check that all fields were populated by the http POST.
echo "about to check if fields are all populsted";
if(isset($_POST['uname']) &&
isset($_POST['fname']) &&
isset($_POST['lname']) &&
isset($_POST['tel']) &&
isset($_POST['dob']) &&
isset($_POST['email1']) &&
isset($_POST['email2']) &&
isset($_POST['pass1']) &&
isset($_POST['pass2'])) {
echo "all fields were populated";
//take values from http POST
$uname = $_POST['uname'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$tel = $_POST['tel'];
$dob = $_POST['dob'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$um->registerUser($uname,$fname,$lname,$tel,$dob,$email1,$pass1);
}
else {
echo "not all fields were populated";
}
?>
UserManagement.php
<?php
require_once('DB_Connect.php');
//Contains functions for all user management related isues i.e. add, remove, edit user.
//only user management - essentially CRM.
class UserManagement
{
echo "entered user management class";
private $conn;
function __construct()
{
echo "user management constructo end";
$db = new DB_Connect();
$this->conn = $db->connect();
echo "user management constructo end";
}
function __destruct()
{
//TODO
}
function registerUser($username,$firstname,$lastname,$telephone,$dob,$email,$password)
{
echo "you chose to register a new user.";
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$sql = "INSERT INTO User(`id`,`username`,`first_name`,`last_name`,`telephone`,`email`,`password`) VALUES (NULL,?,?,?,?,?,?)";
$stmt = $this->conn->prepare($sql);
$stmt->bind_param('ssssss',$username,$firstname,$lastname,$telephone,$email,$encrypted_password);
$result = $stmt->execute();
echo "user added";
echo $result;
$stmt->close();
}
function unregisterUser($uname,$pass1,$pass2)
{
echo "you chose to deregister a user.";
}
public function hashSSHA($password)
{
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
public function checkhashSSHA($salt, $password)
{
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
}
?0
>
DB_Connect.php
<?php
class DB_Connect {
private $conn;
// Connecting to database
public function connect() {
// Connecting to mysql database
require_once('Config.php');
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
>
請在php文件的頂部添加** error_reporing(-1); **以獲取錯誤並在此處分享以幫助:-) –
顯示require_once('DB_Connect.php')的內容;或者刪除該行以進行測試。 –
您的類名是UserManagement,您正在調用$ um-> registerUser –