如何将参数传递给php函数并在html中调用 [英] how to pass parameter to php function and call in html

查看:467
本文介绍了如何将参数传递给php函数并在html中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中有这个功能;一个单独的文件,函数dbRowInsert($ table_name,$ form_data)

我将它包含在我的注册过程中的php文件中。我的问题是我如何调用表单提交函数并将参数传递给 dbRowInsert 函数。这是我的表单数据:

$ $ p $ $ $ $ $ $ $ $ $ $ $'$'$'$'
'password'=> $ password,
'title'=> $ title,
'first_name'=> $ first_name,
'middle_name'=> $ middle_name,
'last_name'=> $ last_name,
'position'=> $ position,
'residence'=> $ residence,
'monthly_salary'=> ; $ monthly_salary,
);

我试过这个方法:

 < form id =signup_formclass =form-horizo​​ntalrole =formaction =<?php dbRowInsert(tblperson,$ form_data)?>> 
...
< / form>


解决方案

将所有内容放在寄存器形式相同的文件中在包含函数php文件之后

$ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ tblperson,$ form_data){
echo< pre>。print_r($ form_data,true)。< / pre>;
}
//包含文件代码结束

if(isset($ _ POST ['submit'])){
$ form_data = array();
$ form_data ['username'] = $ _POST ['username'];
$ form_data ['password'] = $ _POST ['password'];
$ tblperson =person;
//执行操作
dbRowInsert($ tblperson,$ form_data);
}
?>
< form id =signup_formmethod =postclass =form-horizo​​ntalrole =formaction =>
< input type =textname =username/>
< input type =textname =password/>
< input type =submitname =submit/>
< / form>


I have this function in php; a separate file, function dbRowInsert($table_name, $form_data).

I included it in my php file in which registration happens. My problem is how do I call the function on form submit and pass a parameter to the dbRowInsert function. This is the data of my form:

$form_data = array(
    'username' => $username,
    'password' => $password,
    'title' => $title,
    'first_name' => $first_name,
    'middle_name' => $middle_name,
    'last_name' => $last_name,
    'position' => $position,
    'residence' => $residence,
    'monthly_salary' => $monthly_salary,
);  

I tried this method:

<form id="signup_form" class="form-horizontal" role="form" action="<?php dbRowInsert(tblperson, $form_data) ?>">  
...
</form>

解决方案

Put all that in the same file where register form is after including function php file

<?php
//include file code start
function dbRowInsert($tblperson, $form_data){
    echo "<pre>".print_r($form_data,true)."</pre>";
}
//include file code end

if(isset($_POST['submit'])){
    $form_data = array();
    $form_data['username'] = $_POST['username'];
    $form_data['password'] = $_POST['password'];
    $tblperson = "person";
    //do the action
    dbRowInsert($tblperson, $form_data);
}
?>
<form id="signup_form" method="post" class="form-horizontal" role="form" action="">  
    <input type="text" name="username" />
    <input type="text" name="password" />   
    <input type="submit" name="submit" /> 
</form>

这篇关于如何将参数传递给php函数并在html中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆