Php 使用OOP获取表单数据值
我试图创建一个脚本,通过OOP获取表单数据的值,但无法返回和打印这些值。这是我的密码 我还想使用一些动态PHP代码和使用数组的OOP创建动态验证 这是我的signup.php文件Php 使用OOP获取表单数据值,php,Php,我试图创建一个脚本,通过OOP获取表单数据的值,但无法返回和打印这些值。这是我的密码 我还想使用一些动态PHP代码和使用数组的OOP创建动态验证 这是我的signup.php文件 <?php include('inc/form-data.class.php'); $signup_data = new FetchUserData; if(isset($_POST['signup'])) { $signup_data->FetchSi
<?php
include('inc/form-data.class.php');
$signup_data = new FetchUserData;
if(isset($_POST['signup']))
{
$signup_data->FetchSignup('fname_prefix', 'fname', 'uname', 'key',
'ckey', 'gender', 'pnumber', 'country',
'state', 'city', 'zpcode', 'website',
'agreement');
}
?>
这是inc/form-data.class.php
<?php
class FetchUserData
{
private $fname_prefix,
$fname,
$uname,
$key_pass,
$ckey,
$gender,
$pnumber,
$country,
$state,
$city,
$zpcode,
$website,
$agreement,
$values;
public function SignupValuesReturn()
{
return $this->value;
}
public function FetchSignup($fname_prefix, $fname, $uname, $key, $ckey,
$gender, $pnumber, $country, $state, $city,
$zpcode, $website, $agreement)
{
$this->fname_prefix = mysql_real_escape_string($_POST["$fname_prefix"]);
$this->fname = mysql_real_escape_string($_POST["$fname"]);
$this->uname = mysql_real_escape_string($_POST["$uname"]);
$this->key_pass = mysql_real_escape_string($_POST["$key"]);
$this->ckey = $_POST["$ckey"];
$this->gender = mysql_real_escape_string($_POST["$gender"]);
$this->pnumber = mysql_real_escape_string($_POST["$pnumber"]);
$this->country = mysql_real_escape_string($_POST["$country"]);
$this->state = mysql_real_escape_string($_POST["$state"]);
$this->city = mysql_real_escape_string($_POST["$city"]);
$this->zpcode = mysql_real_escape_string($_POST["$zpcode"]);
$this->website = mysql_real_escape_string($_POST["$website"]);
$this->agreement = mysql_real_escape_string($_POST["$agreement"]);
$this->values = array(
'fname_prefix' => $this->fname_prefix,
'fname' => $this->fname,
'uname' => $this->uname,
'key_pass' => $this->key_pass,
'ckey' => $this->ckey,
'gender' => $this->gender,
'pnumber' => $this->pnumber,
'country' => $this->country,
'state' => $this->state,
'city' => $this->city,
'zpcode' => $this->zpcode,
'website' => $this->website,
'agreement' => $this->agreement
);
return $this->values;
}
}
?>
$this->values中缺少一个s:
谢谢,但是你能告诉我如何在类之外使用这些数组值吗?因为它是一个关联数组,就像这样:$result=$signup\u data->signupvaluesreern;,然后您可以这样使用它们:$result['fname_prefix']。感谢您提供的解决方案:您能帮助我如何使用PHP和OOP创建动态验证吗?动态验证是什么意思?比如不添加空的等等,我们只是用同样的东西来创建验证。顺便说一句:不要使用mysql函数,因为它们几乎被弃用了。试试PDO或mysqli。
public function SignupValuesReturn()
{
return $this->values;
}