AncientSage Posted July 22, 2006 Share Posted July 22, 2006 Hello,I believe I am doing this correctly...anyway...[code] $postrows = $_POST['rowsarr']; if(isset($_POST['row'])) foreach($_POST['row'] as $i) unset($postrows[$i]);[/code]Returns me this error: Fatal error: Cannot unset string offsets in /root/includes/functions.php on line 46I get the same error if I don't assign $_POST to a variable. Before I assigned post to a variable, I had this for the unset...unset($_POST['rowsarr'][$i])Note: In the form, a variable containing an array is submitted as the value, would this effect anything? Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/ Share on other sites More sharing options...
JaGeK Posted July 22, 2006 Share Posted July 22, 2006 [quote author=AncientSage link=topic=101508.msg401844#msg401844 date=1153610343]Note: In the form, a variable containing an array is submitted as the value, would this effect anything?[/quote]Obviously the variable ($postrows) contains a string and not an array. What exactly is the goal and why? Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62230 Share on other sites More sharing options...
AncientSage Posted July 22, 2006 Author Share Posted July 22, 2006 [code] foreach($rows as $x => $row) { $arr = unserialize($row); if($arr == ""){ continue; } echo '<input type="checkbox" name="row[]" value="'. $x .'">' . $arr . "<br /> "; echo '<input type="hidden" name="rowarr" value="' . $rows . '">'; echo "<input type=\"hidden\" name=\"checksubmit\">"; echo "<br /><input type=\"submit\" value=\"Delete Selected\">"; echo "</form>"; } [/code]$rows contains a few arrays, it's gathering the from a text file.It's supposed to gather the array, and put it into a text file, that's all good, except this little array problem.So the hidden input would be a string? Do I need to change rowarr to an array, or is it an array by default?Edit: I attempted to put this as... rowsarr[] for the name attribute, will that work? Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62234 Share on other sites More sharing options...
king arthur Posted July 23, 2006 Share Posted July 23, 2006 Well, in your first script you refer to the variable $_POST['rowsarr'] but in the form in the second script you use the name 'rowarr', I don't know if that may have a bearing on your problem? Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62245 Share on other sites More sharing options...
AncientSage Posted July 23, 2006 Author Share Posted July 23, 2006 Yes, that was a problem, thanks for finding it.However, it's still not unsetting the variable, or, at least, not writing it to the text file correct. As it re-writes the entire file (how I have it set), but it's all blank, no text is actualy written.Here is the function I'm calling...[code]function delete_arr_element() { global $root; $textfile = $root . "filelist.txt"; if(isset($_POST['checksubmit'])) { if(isset($_POST['rowsarr'])) { if(isset($_POST['row'])) $rowsarr = $_POST['rowsarr']; foreach($_POST['row'] as $i) unset($rowsarr[$i]); $fp = fopen($textfile, "w"); flock($fp, LOCK_EX); fwrite($fp, $rowsarr . "\n"); flock($fp, LOCK_UN); } } }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62289 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 If $owsarr is an array, you need to do something with the array to make it print, [b]foreach[/b] or [b]implode[/b], otherwise you will just get the word [color=red]array[/color] in your file. How do you want the elements in the array to be written into the file?Ken Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62301 Share on other sites More sharing options...
AncientSage Posted July 23, 2006 Author Share Posted July 23, 2006 Well, the data hasn't been unserialized when it was stored into the $rowsarr variable, would it need to be re-serialized when stored back in?As well, I don't have a need to implement the implode future yet, as I've not added any form of template to it. The data is displayed as...something|something|somethingAt the moment, when I do integrate some form of template, or more features to the script I am writing, I'll explode and implode on the | as well. Quote Link to comment https://forums.phpfreaks.com/topic/15360-deleting-array-element-from-_post/#findComment-62320 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.