Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About TechnoDiver

  • Rank
  1. so I didn't want to start a new thread for this and I couldn't append it to my last post. I'm not trying to be too clever with the program but I decided to try something to help me understand more how data moves between functions. I took the code you've been helping me with and made a function from it -> function check_errors(&$all_errors, $field) { $errors = []; if($errors) { $all_errors = array_merge($errors, $all_errors); return false; } else { return $field; } } it's an internal function to be used in the assign_username, email and pa
  2. That just shot to shit everything I thought I understood about references in this instance. It also taught me to try everything and not assume something won't work because I can't understand how it does. I tried $errors = array_merge(.......); and didn't try $all_errors I just didn't see how it could work that way. Thank you, you've been a great help, but tell me if you don't mind - why $all_errors here? I can't contextualize it working here at all
  3. I had a good chuckle at this. From MY perspective it doesn't seem simpler. I've copied it to analyze it later and I've compared it to your previous example. I've looked over my amended code, based on your first example, and I completely understand it now, thanks for the new example. The reason to reference the variable is more clear now too. I'm working through a tutorial that teaches PHP through a CMS project. I spend some time on the tut then try to transfer that knowledge to a personal project I'm working on, the one this is the eventual registration form for. I've edited my code
  4. Barand, I've been reading about referencing variables and I understand it in principle but maybe not entirely in practice. Not sure I understand the use of it here. I have a few questions if you don't mind - 1) errors[] needs to be assigned within every function that uses it AND in the registration_handler.php as well as be referenced in the parameters? I understand the last 2, but didn't think it needed assigning in each function too 2) What is internally happening with a program when it runs the return false; in the if statement? 3) Would you mind giving me a ELI5 breakdown o
  5. I'm making a registration form and I'm really new at it. I've had a look about at similar issues but feel like I've got my code set up right, I obviously don't. I have a registration_handler.php and a functions.php file. I'm simply trying to pass an array ($errors[]) from the functions that generate them to a function that prints them out on registration_handler.php. It seems so easy, but I'm not getting it. Here's my code: from functions.php: (this is just an example of one of the functions) // USERNAME (MANDATORY) //uses the clean_names() and checks for empty input function
  6. Yea, that works great, maxxd, thank you. The only change I had to make was inserting a forward slash in front of ../config/config.php to make it '/../config.config.php'. In case another user is reading this, it might save them some aggro
  7. Ok, I get that. The doc root is /opt/lampp/htdocs. The path to config.php is /opt/lampp/htdocs/site/config/config.php So do you mean that it's best to move /config/config.php from the /site/ directory to the /htdocs/ directory? Or even outside /htdocs/ to somewhere else?
  8. It wouldn't let me edit my last comment but I realized this absolute path won't work when the site goes live. I'll have to go through and change the paths to config.php when that time comes. It's not outside of doc root. What path format should be used in this situation so the paths won't need to be changed later?
  9. Thanks, I fixed it by adding the entire path - /opt/lampp/htdocs/..... I don't know if it's ideal, but it's working for now
  10. Thanks. I added a line in the config file to echo 'connected to db' and I was seeing that line echoed so thought I was connecting fine. All the error messages told me otherwise. I'm still experiencing some issues with the config.php file though. I'm using XAMPP and my relevant dir structure is: -htdocs |-/site | - /assets |- files you'd expect to find here | - /loginphp | - register.php | - /handlers | - register_handler.php | - config | - config.php It looks to me like the c
  11. This was solved by simply replacing require() with include() which brings more questions. I was under the impression that non critical files should use include and require should be used for critical matters. In my above reg form the config.php file is definitely critical but I get a blank screen after submitting the data if I use require here and everything is fine using include. Why?
  12. I have the following code for a very simple registration form handler - //require('../../config/config.php'); require('reg_functions.php'); //assign clean form variables $firstname = clean_names($_POST['firstname']); $lastname = clean_names($_POST['lastname']); $username = clean_names($_POST['username']); $email = clean_email($_POST['email']); $email2 = clean_email($_POST['email2']); $password = clean_password($_POST['password']); $password2 = clean_password($_POST['password2']); $date = date("Y-m-d"); if(isset($_POST['register_button'])) { //validate
  13. That's really awesome, requinix. I would never have thought to do it that way. This thread really helped me think differently about things. I appreciate the help. I hope I'll be able to contribute knowledge here someday too. Until then I'm sure I'll have more questions. Thanks again Out of curiosity, how would you do it using a foreach loop. I mean, how would you have moved $name into $firstname, $lastname, $username with a foreach loop and a function?
  14. gw1500se, thank you, you've helped me think like a better programmer This is making more sense to me. I was looking at this part and wondering how $name 'got into' $firstname, $lastname etc. and felt this was a weak point. I had this code initially (I'm very new at PHP): //registration form values // //first name // $firstname = strip_tags($_POST['firstname']); //remove html tags // $firstname = str_replace(' ', '', $firstname); //remove spaces // $firstname = ucfirst(strtolower($firstname)); // //last name // $lastname = strip_tags(
  15. Ok, thanks for the replies. The quoted out return in the function was a mistake from editing the copy/paste that I didn't catch before posting, it's not really in the code. Concerning how functions return values, that means that theoretically the following amended code should work: function clean_names($dirty_name) { $dirty_name = strip_tags($dirty_name); $dirty_name = str_replace(' ', '', $dirty_name); $dirty_name = ucfirst(strtolower($dirty_name)); return $dirty_name; } $names = array($firstname, $lastname, $username); if(isset($_POST['register_button']
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.