/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Post Vars in side of a for loop

Hi,I am trying to use POST variables in side a loop, but for some reason, the post data isnt being populated in side my loop but if i echo it before the for loop it is.

Here is an example out put.

[code=php]Array
(
[product1] => 5mm clear toughened glass
[id1] => 134
[width1] => 1000
[height1] => 1000
[price1] => 165.28
[supply1] => supply1
[quantity1] => 1
[Polished_Edges] => 58
[Bevelled_Edges] => 88
[Fixing_Holes] => 26
[Painting] => 168
[powerpoints] =>
[Sandblasting] => 42
[corners] => 40.00
[subtotal2] => 587.28
[gst2] => 73.41
[total2] => 660.69
)

INSERT INTO gm_temp (id,
sid,
prod_id,
prod_name,
dateset,
width,
height,
quantity,
supply,
sundries1,
sundries2,
sundries3,
sundries4,
sundries5,
sundries6,
sundries7,
subtotal)
VALUES (”,
‘3hhq3bb69pmmeo9c8ucphsoqk2′,
”,
”,
’03/05/06-16:25:28’,
”,
”,
”,
”,
”,
”,
”,
”,
”,
”,
”,
”)[/code]

and here is the code that is generating it.

[code=php]
<?php

//error_reporting(E_ALL);

ob_start(“ob_gzhandler”);

session_start();

$sid = session_id();
echo($sid);

setlocale(LC_MONETARY, ‘en_NZ’);

include(‘common/header.php’);

include(‘common/connect.php’);

include(“common/functions.php”);

$dateset = date(“d/m/y-H:i:s”);

echo “<pre>”;
print_r($_POST);
echo “</pre>”;

for ($i=0; $i<7;$i++)
{
if (isset($_POST[“product$i”])) {

$query = “INSERT INTO gm_temp (id,
sid,
prod_id,
prod_name,
dateset,
width,
height,
quantity,
supply,
sundries1,
sundries2,
sundries3,
sundries4,
sundries5,
sundries6,
sundries7,
subtotal)
VALUES (”,
‘”.$sid.”‘,
‘”.$_POST[‘id$i’].”‘,
‘”.$_POST[‘product$i’].”‘,
‘”.$dateset.”‘,
‘”.$_POST[‘width$i’].”‘,
‘”.$_POST[‘height$i’].”‘,
‘”.$_POST[‘quantity$i’].”‘,
‘”.$_POST[‘supply$i’].”‘,
‘”.$_POST[‘sundries1$i’].”‘,
‘”.$_POST[‘sundries2$i’].”‘,
‘”.$_POST[‘sundries3$i’].”‘,
‘”.$_POST[‘sundries4$i’].”‘,
‘”.$_POST[‘sundries5$i’].”‘,
‘”.$_POST[‘sundries6$i’].”‘,
‘”.$_POST[‘sundries$i’].”‘,
‘”.$_POST[‘subtotal’].”‘)”;

$result = mysql_query($query);
if(!$result){

echo(“not added in to the temp db:<br />”.mysql_error().”<br />”.”r”.”<hr />”);

}
}
}

echo “<pre>”;
print_r($query);
echo “</pre>”;

//header(“Location: cart.php”);

?>

[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonMay 03.2006 — In the following chunk of code:[code=php] VALUES ('',
'".$sid."',
'".$_POST['id$i']."',
'".$_POST['product$i']."',
'".$dateset."',
'".$_POST['width$i']."',
'".$_POST['height$i']."',
'".$_POST['quantity$i']."',
'".$_POST['supply$i']."',
'".$_POST['sundries1$i']."',
'".$_POST['sundries2$i']."',
'".$_POST['sundries3$i']."',
'".$_POST['sundries4$i']."',
'".$_POST['sundries5$i']."',
'".$_POST['sundries6$i']."',
'".$_POST['sundries$i']."',
'".$_POST['subtotal']."')";[/code]
You need to use double quotes in the array keys to interpolate (I think that's the word) the variable [I]$i[/I]. So it wouldn't be [code=php]$_POST['id$i'][/code]it would be [code=php]$_POST["id$i"][/code]And so on...

BTW-- In your $_POST array, you don't even have any values that resemble sundries11, sundries21, etc.

Good Luck,

--Steve
Copy linkTweet thisAlerts:
@SheldonauthorMay 05.2006 — Thanks , ill give that a go
Copy linkTweet thisAlerts:
@SheldonauthorMay 05.2006 — Thanks, That worked,
Copy linkTweet thisAlerts:
@balloonbuffoonMay 05.2006 — No problem!

--Steve
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...