We help IT Professionals succeed at work.

PHP $_POST Variable with brackets

Robert Granlund
on
81 Views
Last Modified: 2019-03-01
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?
Comment
Watch Question

Author

Commented:
@ron, can you please show me that written out in the format I have?  I'm a little over my head right now.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

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

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

Author

Commented:
@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
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.