how to handle an array of values sent through a POST request
In action in form data define another php file name where u need to send data
iterates over the elements of the $influencer_admin_ids array inside form data
inside loop generates hidden input fields have have the name attribute set to "influencer_email[]" to create an array of values
in another php file to get array value use json encode
step1:
a PHP array or data structure.
["influencer_name"] => array(4) {
[0] => string(4) "Amit"
[1] => string(6) "Roshan"
[2] => string(6) "Roshan"
[3] => string(16) "Roshan kumar jha"
}
This code is typically used in a web application to process form submissions. It checks if certain form fields are set in the $_POST data, and if they are, it assigns their values to corresponding PHP variables. These variables can then be used for further processing, such as database operations, calculations, or generating responses
include "DBConnection.php";
if(isset($_POST["admin_id"]))
{
$create_date = date("Y-m-d");
$name = $_POST["influencer_name"];
$org_slug = $_POST["org_slug"];
$admin_id = $_POST["admin_id"];
$email = $_POST["admin_email"];
$influencer_emails = $_POST["influencer_email"];
}
step2:
sends array of value to another php file
<form method="post" enctype="multipart/form-data" action="pgRedirect.php">
<?php
foreach ($influencer_admin_ids as $index => $admin_id) {
echo '<input type="hidden" name="influencer_admin_id[]" value="' . $admin_id . '" />';
}
?>
<input type="hidden" name="admin_id" id="" placeholder="Enter Your Name" value="<?php echo $admin_id; ?>"/>
<input type="hidden" name="user_name" id="" placeholder="Enter Your Name" value="<?php echo $user_name; ?>"/>
<?php
foreach ($influencer_emails as $index => $admin_email) {
echo '<input type="hidden" name="influencer_email[]" value="' . $admin_email . '" />';
}
?>
<input type="hidden" name="org_slug" id="" placeholder="Enter Your Name" value="<?php echo $org_slug; ?>"/>
</form>
step3
how to handle an array of values sent through a POST request
if(isset($_POST["name"])){
var_dump($_POST);
$create_date = date("Y-m-d");
$name = $_POST["name"];
$EMAIL = $_POST["EMAIL"];
$MSISDN = $_POST["MSISDN"];
$influencer_admin_ids = $_POST["influencer_admin_id"];
$influencer_admin_id = json_encode($influencer_admin_ids);
$admin_id = $_POST["admin_id"];
$user_name = $_POST["user_name"];
$org_slug = $_POST["org_slug"];
$influencer_email_json = $_POST['influencer_email'];
}
step4:
SQL INSERT query and then executes the query to insert data into a database table.
$sql = "INSERT INTO `payment_paytm`(payment_id,influencer_admin_id,amount,payment_status,admin_id,user_name,Pay_date,org_slug,admin_email,influencer_email,influencer_name) VALUES('$ORDER_ID','$influencer_admin_id','$TXN_AMOUNT','approved','$admin_id','$user_name', '$create_date','$org_slug','$EMAIL', '$influencer_email', '$name')";
$result = $con->query($sql);
output
Top comments (0)