sodascape Posted November 16, 2006 Share Posted November 16, 2006 I'm having issues getting all of the variables of an array into a session, I put four or five things in, save it to a session and it only prints out the first one when I call it. What is the best way to fix this? Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/ Share on other sites More sharing options...
SharkBait Posted November 16, 2006 Share Posted November 16, 2006 Can you show us the code that deals with the array and inserting the values into a session? Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125379 Share on other sites More sharing options...
sodascape Posted November 16, 2006 Author Share Posted November 16, 2006 The input tag from the form:[code]<input type="checkbox" name="store[]" value="blue" /><input type="checkbox" name="store[]" value="red" /><input type="checkbox" name="store[]" value="green" />[/code]Turning the array into a session[code]// TURNING THE ARRAY INTO A SESSION$_SESSION['bag'] = $_POST['store']; [/code]PUTTING THIS INTO THE DATABASE WITH OTHER VARIABLES NOT IN THE ARRAY[code] // UPLOAD THIS SHTuff TO THE DATABASE STORE mysql_connect('localhost','stickys_stsp','stsp'); mysql_select_db( 'stickys_vbase' ); // DUMP ARRAY OUT OF SESSION foreach ($_SESSION['bag'] as $bag) { echo '<td align="center"><img src="setcaps/'.$bag.'" border="1" alt="" /></td>'; $storebag = "INSERT INTO store (id, username, setcap, today, expires, key) VALUES (0, $user, $bag, 0, 0, $key)"; // Display Results $bagr = mysql_query ($storebag); } // end foreach[/code] Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125382 Share on other sites More sharing options...
sodascape Posted November 16, 2006 Author Share Posted November 16, 2006 Anyone have any idea? This is driving me nuts!?!?! Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125432 Share on other sites More sharing options...
JasonLewis Posted November 16, 2006 Share Posted November 16, 2006 try print_r the store checkbox once you have submitted, then once the session is set do the same thing, to see if all variables have been passed correctly. Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125435 Share on other sites More sharing options...
sodascape Posted November 16, 2006 Author Share Posted November 16, 2006 [code]Array ( [0] => red.jpg [1] => green.jpg [2] => blue.jpg )[/code]THAT'S WHAT I GET WHEN I PRINT_R THE ARRAY[code]Array ( [0] => red.jpg [1] => green.jpg [2] => blue.jpg )[/code]THAT'S THE RESPONSE I GET WHEN I PRINT_R THE SESSION.EVERYTHING SEEMS TO BE passing fine. Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125438 Share on other sites More sharing options...
btherl Posted November 16, 2006 Share Posted November 16, 2006 Try this to replace your mysql_query():[code=php:0]$bagr = mysql_query ($storebag) or die("Error in $storebag: " . mysql_error());[/code]Can you tell us where you are finding only one item instead of all three items? Link to comment https://forums.phpfreaks.com/topic/27411-arrays-and-sessions/#findComment-125452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.