I have a class which is maintain guest information. So in that class I have following method to insert guest data into a guest_info
table
require_once "BaseModel.php";
class GuestModel extends BaseModel
{
public static $table = "guest_info";
public static function guestInfoFormData(){
$title = $_POST['title'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$nicpassport = $_POST['nicpassport'];
$contactnumber = $_POST['contactnumber'];
$addressline1 = $_POST['addressline1'];
$addressline2 = $_POST['addressline2'];
$addressline3 = $_POST['addressline3'];
$country = $_POST['country'];
$guestinfo = array($title,$firstname,$firstname,$nicpassport,$addressline1,$addressline2,$addressline3,$country);
insertInto($guestinfo);
}
}
How can I call this method from my HTML form and pass the guest data to it?
<?php GuestModel::guestInfoFormData(); ?>
确保在GuestModel
之前需要/包括GuestModel
类。
You can use GuestModel::guestInfoFormData()
, but you can't do it in a html
file, it has to be a php file.
Don't forget to escape all input values, now you pass all user input to insertInto
, so you have to escape the data before using them in a sql query to prevent sql injections.
Btw: Why you create a class, when you call a global function from it? Maybe it's a good idea to move the global function insertInto
into this (or another, better) class :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.