Skip to content Skip to sidebar Skip to footer

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 cal

Solution 1:

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.


Solution 2:

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>

Post a Comment for "How To Pass Parameter To Php Function And Call In Html"