我有一个表单。 (和registration.php)将数据保存到数据库中使用类
<form action="reservation.php" onsubmit="return validateForm()" class="pure-form" id="form" method="POST">
<label for="initials">Initials:</label><input type="text" name="initials" id="initials" placeholder="initials" required><br />
<label for="firstname">First name:</label><input type="text" name="firstname" id="firstname" placeholder="firstname" required><br />
<label for="surname">Surname:</label><input type="text" name="surname" id="surname" placeholder="surname" required><br />
<label for="country">Country:</label><input type="text" name="country" id="country" placeholder="country" required><br />
<label for="state">State:</label><input type="text" name="state" id="state" placeholder="state" ><br />
<label for="province">Province:</label><input type="text" name="province" id="province" placeholder="province" required><br />
<label for="city">City:</label><input type="text" name="city" id="city" placeholder="city" required><br />
<label for="houseadress">Houseadress:</label><input type="text" name="houseadress" id="houseadress" placeholder="houseadress" required><br />
<label for="phone">Phone:</label><input type="text" name="phone" id="phone" placeholder="phone" required><br />
<label for="email">E-mail:</label><input type="text" name="email" id="email" placeholder="email" required><br />
<input type="submit" value="register" name="register">
</form>
而且我有一个类:(client.class.php)
class Client{
private $clientID;
private $initials;
private $name;
private $surname;
private $country;
private $state;
private $province;
private $city;
private $houseadress;
private $phone;
private $email;
public function __construct($clientID, $initials, $name, $surname, $country, $state, $province, $city, $houseadress, $phone, $email) {
$this->clientID = $clientID;
$this->initials = $initials;
$this->name = $name;
$this->surname = $surname;
$this->country = $country;
$this->state = $state;
$this->province = $province;
$this->city = $city;
$this->houseadress = $houseadress;
$this->phone = $phone;
$this->email = $email;
}
}
和一个数据库连接:(database.php中)
class Database {
public $pdo;
public function __construct() {
// Connection information
$host = 'localhost:3307';
$dbname = 'californiahotel';
$user = 'root';
$pass = 'usbw';
// Attempt DB connection
try
{
$this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo 'Successfully connected to the database!';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function __destruct()
{
// Disconnect from DB
$this->pdo = null;
//echo 'Successfully disconnected from the database!';
}
}
我已经在寻找几个星期来了解如何将表单数据传递给类(客户端),然后到类(数据库),然后将其保存到数据库!但我没有找到任何我需要的东西。 也许有人可以解释它是如何做到的?
你有一个表,这可能会存储这些信息在数据库中? – 2014-10-22 08:15:10
我有一个数据库的所有列作为窗体!命名客户端。 – 2014-10-22 08:16:58
是的,我认为你可以使用整个对象来插入它,但我不知道它是否可以在私有属性上工作。只是尝试它 – Ghost 2014-10-22 08:18:51