我有一個表單。 (和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