WesleyA 0 Posted May 21, 2015 Report Share Posted May 21, 2015 I want to add elements by the browser into an array with the name $map I wrote the next piece of code for this: <?php $var = $_POST["var"]; function addIntoArray($var) { global $map; if (($var != ".") || ($var != "..")) { array_push($map, $var); echo $var . " succesfully added to the array!"; } return; } ?> The problem though, is not having an error code, but the screen just does not give an output at all while I did make an echo line. Whats going wrong here? Quote Link to post Share on other sites
Techneut 2 Posted May 21, 2015 Report Share Posted May 21, 2015 (edited) 1. Make sure you check for the existence of the input field with <?php if (isset($_POST['var']) { $var = $_POST['var']; function addIntoArray($var) { global $map; if (!empty($var)) { $map[] = $var; echo $var." succesfully added to the array!"; } return; } }?> Edited May 21, 2015 by Techneut Quote Link to post Share on other sites
justsomeguy 1,135 Posted May 21, 2015 Report Share Posted May 21, 2015 Are you actually executing that function? Where's the rest of the code? Where is $map defined and where do you execute the function? Quote Link to post Share on other sites
WesleyA 0 Posted May 21, 2015 Author Report Share Posted May 21, 2015 (edited) I have it running. But I had to call the function addIntoArray($var) Now I want to check if the variable is added to the array. I already had an array, with elements and I want to print the entire array with its content on the screen. It is not that I cant find the codes. My problem when programming is that I dont know much about the principles, such as type signature, declaration, definition. Are there any resources online that explain more about these logic that is behind a programming language like specifically PHP? Edited May 21, 2015 by WesleyA Quote Link to post Share on other sites
justsomeguy 1,135 Posted May 26, 2015 Report Share Posted May 26, 2015 The PHP documentation is probably a good place to start, go through the Language Reference section.http://php.net/manual/en/If you're looking for something that is more instructional, then maybe a book like Programming PHP. Check the PHP section at oreilly.com to see a list. Quote Link to post Share on other sites
WesleyA 0 Posted May 27, 2015 Author Report Share Posted May 27, 2015 Ok thanks I was there already. The problem too is that since last year programmers work with the mysqli extension instead of mysql, so the php book (in my own language which is NOT present @ php.net) I bought became partly useless. But I quited this array_push matter meanwhile. I switchted to MYSQL giving me more chance to find scripts etc and more structure in a more complex built database. Quote Link to post Share on other sites
thescientist 231 Posted May 27, 2015 Report Share Posted May 27, 2015 are you saying you have a book that uses the mysqli extension and you still decided to use mysql instead? I would highly discourage that, mysql is deprecated, at minimum you should be using mysqli, or even better, PDO. Quote Link to post Share on other sites
WesleyA 0 Posted May 27, 2015 Author Report Share Posted May 27, 2015 @thescientist: NO, exactly the opposite. But i dont think the book is released in in any other than my own (dutch). Quote Link to post Share on other sites
justsomeguy 1,135 Posted May 27, 2015 Report Share Posted May 27, 2015 The mysql extension does not have any benefits over the mysqli extension (or PDO). There is a reason mysql was replaced with mysqli (it was replaced in 2003, actually). Quote Link to post Share on other sites
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.