Avatar of Robert Granlund
Robert Granlund
Flag for United States of America asked on

PHP $_POST Variable with brackets

PHP the correct way to create a form variable to insert into a DB

my form has this:

<html>
  <textarea name="ii_pi_name[]" value="<?= $ii_pi_name1 ?>" ></textarea>

Open in new window


My PHP has this but it is not working.
<?php
$ii_pi_name = $_POST['ii_pi_name'][''];

Open in new window

How do I write that so it works with the bracket?
PHP

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Robert Granlund

ASKER
@ron, can you please show me that written out in the format I have?  I'm a little over my head right now.
Ron Malmstead

name = htmlspecialchars($_POST['ii_pi_name’])

This is actually the correct way I was having brain drain moment on my previous post
Robert Granlund

ASKER
@ron, so you are saying this:

$ii_pi_name =  htmlspecialchars($_POST['ii_pi_name']);  When an array is being passed? Because that does not work to insert that var into the DB
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
skullnobrains

array_pop($_POST['ii_pi_name']) will give you the first elt of the array

the array has no keys so php indexes it numerically, so the first elt is actually $ii_pi_name = $_POST['ii_pi_name'][0];

when in doubt, just print the whole thing with var_export or var_dump or even print_r
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.