WesleyA Posted May 21, 2015 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? Link to comment Share on other sites More sharing options...
Techneut Posted May 21, 2015 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 21, 2015 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? Link to comment Share on other sites More sharing options...
WesleyA Posted May 21, 2015 Author 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2015 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. Link to comment Share on other sites More sharing options...
WesleyA Posted May 27, 2015 Author 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. Link to comment Share on other sites More sharing options...
thescientist Posted May 27, 2015 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. Link to comment Share on other sites More sharing options...
WesleyA Posted May 27, 2015 Author 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). Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2015 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). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now