Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

how to pass parameter to php function and call in html

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

PHP is not written like JavaScript; a POST request must be sent to a PHP page for processing (unless you're using AJAX), like so

<form method="POST" action="process.php">
....
</form>

In process.php, you have to extract out the fields you want to send to the function.

$username = $_POST['username'];
doSomethingWIthUserName($username);

Or in you case, since you are sending the entire array:

dbRowInsert("tblHelpers", $_POST);

Here's a detailed tutorial on handling POST requests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...