Link to home
Create AccountLog in
Avatar of Robert Granlund
Robert GranlundFlag 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?
Avatar of Robert Granlund
Robert Granlund
Flag of United States of America image

ASKER

@ron, can you please show me that written out in the format I have?  I'm a little over my head right now.
Avatar of Ron Malmstead
name = htmlspecialchars($_POST['ii_pi_name’])

This is actually the correct way I was having brain drain moment on my previous post
@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
Avatar of skullnobrains
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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account