BrettCarr Posted March 20, 2010 Share Posted March 20, 2010 Hi people I have a ajax send that sends an php $SESSION array to the server side does some stuff adds the records to the mysql database This all works fine My problem is that when the ajax php is done i want to clear the $_SESSION['batcharray'] with unset. So i thought i would send a repsonse back from ajax with the number 1 in it and if it is one clear the $_SESSION['barcharray'] So the user can start a new batch of records.. But it keeps clearing it not allowing me to add anymore records I am totally lost. I haven't posted code becuase i have no idear and i would be waisting your time any advice would be great im desperate Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 just use $_SESSION['barcharray'] = that should work and replace the original one. Quote Link to comment Share on other sites More sharing options...
BrettCarr Posted March 20, 2010 Author Share Posted March 20, 2010 just use $_SESSION['barcharray'] = that should work and replace the original one. ok im doing this function addDatadbRecv(data) { $_SESSION['batcharray'] = data; } But i get this is the responce tab $_SESSION is not defined $_SESSION['batcharray'] = data; Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 have you used session_start(); yet? Quote Link to comment Share on other sites More sharing options...
BrettCarr Posted March 20, 2010 Author Share Posted March 20, 2010 have you used session_start(); yet? yep its at the top of the page Thank you helping im so lost Quote Link to comment Share on other sites More sharing options...
trq Posted March 20, 2010 Share Posted March 20, 2010 Can you stop posting within tags? Its allot harder to read than the standard text. Post some code. (Within tags) Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Could you please post your code? Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Can you stop posting within tags? Its allot harder to read than the standard text. Post some code. (Within tags) or within code Quote Link to comment Share on other sites More sharing options...
BrettCarr Posted March 20, 2010 Author Share Posted March 20, 2010 Could you please post your code? function addDatadb() { myarray = <?= json_encode($_SESSION['batcharray']) ?>; send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , addDatadbRecv ); } function addDatadbRecv(data) { $_SESSION['batcharray'] = data; } this is whats in ajax/arrayclean.php <?PHP include_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.php'); $db = new Database(); $db->connect(); $batcharry = $_REQUEST['myarray']; $parts = array_map(create_function('$e', 'return implode("','", $e);'), array_chunk(explode(',', $batcharry), 13)); //var_dump($parts); foreach ($parts as $value) { $comma_separated = implode("','", $value); //var_dump($comma_separated); eval("\$comma_separated = \"$comma_separated\";"); $myquery = "INSERT INTO batch_import VALUES(null,'$comma_separated','0');"; //echo $myquery . "<br />"; $db->query($myquery); } if (isset($_REQUEST['myarray'])) { unset($_REQUEST['myarray']); echo $_REQUEST['myarray']; } ?> so when$_REQUEST['myarray'] is emptied im sending back to client side and want to replace whatsin $_SESSION['batcharray'] with whats in data.... nothing Quote Link to comment Share on other sites More sharing options...
trq Posted March 20, 2010 Share Posted March 20, 2010 If this is Javascript (which it looks like) function addDatadb() { myarray = <?= json_encode($_SESSION['batcharray']) ?>; send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , addDatadbRecv ); } function addDatadbRecv(data) { $_SESSION['batcharray'] = data; } $_SESSION means nothing to it. You'll need to clear $_SESSION['batcharray'] on the server. Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 It is Javascript... and secondly i see no session_start(); there, maybe you should add it. Quote Link to comment Share on other sites More sharing options...
BrettCarr Posted March 20, 2010 Author Share Posted March 20, 2010 It is Javascript... and secondly i see no session_start(); there, maybe you should add it. Cool you were right session_start() was the problem i didn't have it in the ajax file..... Thanks Man.. Now its beer time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.