Posting array information into php
Posted: Mon Apr 13, 2009 2:33 pm
Hi,
I am new to PHP and I am trying to import information from an Array using the POST method, below is my code;
The variables I am posting in are style names of shirts coming from a shopping cart.
My intention is to create a new variable - $stylename0, $stylename1, $stylename2 etc etc for each of the items I am posting in from the shopping cart array(externally).
I will then post these into my SQL database.
The problem I am having is indexing the new $stylename variables so that they have the number that the loop is currently at in the name.
Any help would be greatly appreciated.
<?php
//register.php
include "connect.php";
if (isset($_POST['username']))
{
$arraylength = ($_POST['arraylength']);
for ($num=0; $num <= $arraylength; $num++ )
{
$stylename.$num = $_POST['stylename'.$num];
echo "result=$stylename.$num";
}
}
?>
I am new to PHP and I am trying to import information from an Array using the POST method, below is my code;
The variables I am posting in are style names of shirts coming from a shopping cart.
My intention is to create a new variable - $stylename0, $stylename1, $stylename2 etc etc for each of the items I am posting in from the shopping cart array(externally).
I will then post these into my SQL database.
The problem I am having is indexing the new $stylename variables so that they have the number that the loop is currently at in the name.
Any help would be greatly appreciated.
<?php
//register.php
include "connect.php";
if (isset($_POST['username']))
{
$arraylength = ($_POST['arraylength']);
for ($num=0; $num <= $arraylength; $num++ )
{
$stylename.$num = $_POST['stylename'.$num];
echo "result=$stylename.$num";
}
}
?>