我创建了一个类,然后创建了一个调用该类的php实例以注册用户,提交表单时出现500错误。建议我在插入语句中添加`,但还是不行。
我已经被告知这是不安全的,但这只是让我学习一些基本的oop php
我对此很陌生,所以请不要告诉我这是重复的/不正确的并报告我的帖子。我只需要一些指导即可
文件使用情况如下:
dbconnection:
<?php
class databaseConnection {
private $host;
private $databasename;
private $username;
private $password;
public $mysqli;
public $testquery;
public $results;
//forcing the data to be given to the object (using the constructor)
public function __construct(){
$this->databaseconnect();
}
public function __destruct(){
mysqli_close($this->databaseConnect);
}
private function databaseConnect(){
$this->host = 'localhost';
$this->username='***';
$this->password='***';
$this->databasename='*****';
$this->mysqli= new mysqli($this->host,$this->username,$this->password,$this->databasename);
if ( $this->mysqli){
echo 'OK';
}else {
echo 'error';
echo $this -> mysqli -> error;
}
}
}
?>
file2:
<?php
require_once ('dbconnect.php');
$myDatabase = new databaseConnection();
class RegisterUser{
public function registration($CustomerID,$Username,$Password,$Name,$Surname,$MobilePhone,$HomeAddress,$City,$Country,$SecurityQuestionID,$SecurityAnswer,$email){
$register_user=$myDatabase->query("INSERT INTO `Customer`(`CustomerID`,`Username`,`Password`,`Name`,`Surname`,`MobilePhone`,`HomeAddress`,`City`,`Country`,`SecurityQuestionID`,`SecurityAnswer`,`email`)
VALUES ('$CustomerID','$Username','$Password','$Name','$Surname','$MobilePhone','$HomeAddress','$City','$Country','$SecurityQuestionID','$SecurityAnswer',$email)");
return $register_user;
}
}
?>
文件3:
<?php
include "AddNewCustomer.php";
$RegisterUser = new RegisterUser();
if (isset($_POST['submit']))
{
$CustomerID = $_POST['CustomerID'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Name = $_POST['Name'];
$Surname = $_POST['Surname'];
$MobilePhone = $_POST['MobilePhone'];
$HomeAddress = $_POST['HomeAddress'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$SecurityQuestionID = $_POST['SecurityQuestionID'];
$SecurityAnswer = $_POST['SecurityAnswer'];
$email = $_POST['email'];
$RegisterUser->registration($CustomerID,$Username,$Password,$Name,$Surname,$MobilePhone,$HomeAddress,$City,$Country,$SecurityQuestionID,$SecurityAnswer,$email);
echo "Please note that you have registered an account Succesfully with Eutopia Train System";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Registration Form</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div class="wrapper">
<form action="" method="POST">
<input type="text" name="CustomerID" placeholder="CustomerID"/><br>
<input type="text" name="Username" placeholder="Username"/><br>
<input type="text" name="Password" placeholder="Password"/><br>
<input type="text" name="Name" placeholder="Name"/><br>
<input type="text" name="Surname" placeholder="Surname"/><br>
<input type="text" name="MobilePhone" placeholder="MobilePhone"/><br>
<input type="text" name="HomeAddress" placeholder="HomeAddress"/><br>
<input type="text" name="City" placeholder="City"/><br>
<input type="text" name="Country" placeholder="Country"/><br>
<input type="text" name="SecurityQuestionID" placeholder="SecurityQuestionID"/><br>
<input type="text" name="SecurityAnswer" placeholder="SecurityAnswer"/><br>
<input type="text" name="email" placeholder="email"/><br>
<input type="submit" value="submit" name="submit" class="btn"/>
</form>
</div>
</body>
</html>