【发布时间】:2014-10-22 08:11:55
【问题描述】:
我有一个表格。 (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!';
}
}
我一直在寻找几个星期来了解如何将表单数据获取到类(客户端),然后到类(数据库),然后将其保存到数据库!但我没有找到我需要的任何东西。 也许有人可以解释它是如何做到的?
【问题讨论】:
-
你有一个表,可以将这些信息存储在数据库中吗?
-
我有一个数据库,所有的列都是表格!指定客户。
-
是的,我认为您可以使用整个对象来插入它,但是我不确定它是否适用于私有属性。试试吧