/    Sign up×
Community /Pin to ProfileBookmark

session array post problem

i have this line of code:

[code=php]$edit_row = mysql_query(“SELECT * FROM {$_SESSION[‘tbl_selection’]} WHERE id = {$_POST[‘edit_row’]}”);[/code]

I am using checkboxes to post to this section. Problem is only the last check box is posting it’s ‘id’. the code works fine except if I have multiple selections in the checkboxes, there is only one sent.

How do I get all the selections within this query.

id = 1, 2, 3, …

instead of

id = 3

hopefully this make sense – thx

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsAug 15.2005 — setup your <input> 's like this&lt;input type="checkbox" name="box[]" value=""&gt;then, when the for is submitted, the $_POST['box'] will contain an array of all the checked box values
Copy linkTweet thisAlerts:
@rch10007authorAug 15.2005 — ...more about the problem!

I just figured out that the reason I am only getting one selection is because the session key is the same. So when I try to transfer the $_POST variables into $_SESSION variables, it won't work since all the $key's are the same so the $value just takes on the last value.

I suppose I am just rewrting the session variable over and over (with foreach())until the last value and that is the one it keeps.

So how, do I get all the posted variables into an array that I can include in the query statement?

hmmm...
Copy linkTweet thisAlerts:
@rch10007authorAug 15.2005 — thx SD,

i already have the code as such:
[code=php]<input type="checkbox" name="delete_row[]" value="{$_SESSION['id']}" />[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsAug 15.2005 — no problem

you can build a query like this[code=php]<?php
$ids = array(1, 10, 5, 2);
$sql = "DELETE FROM table WHERE";
$s = '';

foreach($ids as $id)
{
$sql .= $s . " id = '$id'";
$s = " OR";
}
echo $sql; // output: DELETE FROM table WHERE id = '1' OR id = '10' OR id = '5' OR id = '2'
?>[/code]
Copy linkTweet thisAlerts:
@rch10007authorAug 15.2005 — ok, this is what I have - I know it won't work properly since {$_SESSION['id']} is after id in the query, but for now i leave it there because it outputs that row.

After the foreach statement, I echo the results.

The results of that echo is: [B]Array12[/B]

so the question is, how do i get that to output 1,2 so I can stick it int he query?

[code=php]

foreach ($_POST['edit_row'] as $value)
{
$edit_row .= $value;
}
echo ( $edit_row);

mysql_select_db("{$_SESSION['db_selection']}");

$edit_row = mysql_query("SELECT * FROM {$_SESSION['tbl_selection']} WHERE id = {$_SESSION['id']}");
[/code]


How do you "load" an array with $_POST variables???
Copy linkTweet thisAlerts:
@bokehAug 15.2005 — Temporarily change: [code=php]echo ( $edit_row);[/code] to: [code=php]print_r($edit_row);[/code]
Copy linkTweet thisAlerts:
@rch10007authorAug 15.2005 — I sort of have it working now!!!

[code=php]
if ($_POST['edit_row'] || $_POST['delete_row'])
{

foreach ($_POST['edit_row'] as $key => $value)
{

$edit_rows .= $value . ",";
}
echo rtrim($edit_rows, ",");
[/code]


This makes the echo: [B]1,2[/B]

Now I have to implement this into the query

thx for the replies
×

Success!

Help @rch10007 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.17,
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,
)...