r/PHPhelp • • May 12 '20

Beginner Struggling

Hi there o/

So for the last two weeks or so i've been attempting to learn php i've been watching several youtube tutorials couldn't tell you how many hours now and reading websites such as guru99 and w3schools. I feel like im starting to understand the language but i'm failing to materialse it into anything.

I just end up going back and rewatching or re-reading. I come from a html/css background nothing outside of that language wise.

I'm never quite sure where to start off. I was just wondering if anyone has any advice on how to get myself going and producing code.

Or any resources to give me that extra push.

15 Upvotes

46 comments sorted by

5

u/doodooz7 May 12 '20

Best way to learn is to do. Just build something simple. How about like a math calculator?

3

u/Yamiik May 12 '20

Thanks for the reply, yeah probably best to just do and start small.

3

u/doodooz7 May 12 '20

Come back here for help

4

u/Yamiik May 12 '20

Thank you :), hope everything is good during these hard times!

1

u/Yamiik May 14 '20

Hey, so i've been working on a sort of "profile" page, i've got the login/register done along with auth the user to remember the session.

The problem i'm having at the moment is i want the ability for a user to enter their information in a textarea which i have written up in the html/php and it's showing in the DB but i was unable to get it to show in the index page and just reverted all my code as i was getting constant errors

Any advice on this?

https://pastebin.com/K2Hr28Cy < code

1

u/Yamiik May 14 '20

I'm not sure if i need it to be called from the DB in the login.php or what im kinda confused here haha

1

u/Yamiik May 14 '20

<textarea type="text" name="information" id="information" rows="10" cols="30">Profile Information...</textarea>

The html if needed

1

u/Astaltar May 12 '20

Oh, it's not really simple task. You can try to write it by yourself. E.g parse and calculate expression "2+2*2" from the string. Or do you mean something else ?

4

u/nudi85 May 12 '20 edited May 12 '20

Write code. Write as much code as you can after completing each video.

Sounds like PHP is your first language. I would advise you to keep the project ideas you have in the back of your head for now and not try to make them your goal. It'll be nothing but frustrating otherwise since you're not going to make much progress otherwise.

Instead, just play around with the thing you've just learned. As much as possible. Combine it with the things you've learned before. Write silly programs.

I can remember when I first read about the setTimeout() function (JavaScript) like 20 years ago. First, I just made some text appear after 6 seconds saying "What are you waiting for?" It was hilarious to my twelve year old self. Next, I made it appear after a random amount of time. Then I allowed the user to enter the number of seconds they wanted to wait for and customize the message.

This ended up being the first thing I ever put online. And evey time I learned something new, I would try and put it into that silly waiting website.

I think that if I had some grand project in mind from the beginning, I would've been frustrated by not making enough progress towards it.

So, to sum up: code as much as you can after each and every lesson and let the things you've learned shape the "projects" you're making - not the other way around. At least not in the beginning.

Edit: setTimeout() is a JavaScript function, not a PHP one.

1

u/Yamiik May 12 '20

First off thanks for even reading and replying.

Sounds like great advice i suppose i could just learn > code > learn > add type of structuce, that way it will grow into something and im praciticing and combining things and yes php is my first language.

Sounds like you had a good old time with the setTimeout () haha

1

u/Zyycyx May 12 '20

Just don't forget that you can build interesting things with PHP. So don't do this learn > write some code > learn > write some code.
What I did is that I learned some fundamental things about PHP and then started a project on the side. If I learned something what I tought it's useful for my project, I implemented it there.

1

u/Yamiik May 13 '20

Just want to say a big thanks for everyone taking their time to help me out and give me some advice much appreciated!

1

u/RecalledBurger May 12 '20

Same here. I'm currently going through a Udemy course (Edwin Diaz), which is great but I'm constantly rewatching his videos to solve his end of chapter assessments. I feel like nothing sticks, coding requires a lot more interpretive skills than HTML or CSS combined, those mark-up languages are just elementary, honestly. When I'm done with the course I plan to head dive into a project idea I've been thinking about, even if it's leafing through a book or rewatching tutorials like crazy to get it done (which is how I learned HTML and CSS anyway).

1

u/Yamiik May 12 '20

Yeah i have a pretty pbbg game project that i've had in my head the past few years, now i have the time to actually go at it. Sadly now im struggling to get it started.

2

u/OOPGeiger May 12 '20

This is the right thing to do.

1

u/OOPGeiger May 12 '20

Create a database with a name field, password, description, and maybe profile image.

Next create a login page with an html form and use PHP to cross reference names and passwords entered into that form with values stored in the database. If the name and password matches a row in the table then turn all the data in that row into PHP variables and display them on the next page. You will be doing this more than anything else when using PHP. Make it so you can login as different people and once logged in you can see all of their information on the screen in front of you. If you take that database data and turn it into session variables instead of regular variables, you have now create a complete login system!

2

u/halfercode May 12 '20

This is a nice idea, but it is worth noting that login is one of the hardest things to get right. One can develop a working system containing SQL injection, unhashed and unsalted passwords, XSS vulns that permit cookie stealing, etc. The OP should still do it, but we should warn them that it should not be put online.

2

u/OOPGeiger May 12 '20

I mean as a 'learning' project yes. Since their is so much that goes into a login system, you best get started learning it right now.

2

u/Yamiik May 13 '20

Yeah i'm currently working on a login right now, just having some problems getting it to connect to the DB and save the data.

I will of course not use this online as i'm still get to look into security.

1

u/Yamiik May 14 '20

Hey any ideas how to return a textarea, I have it going into the DB as they register but i cannot figure out how to display it after they've logged in.

Basically i'm making a sort of "profile", at the register they enter username/email/password and then enter some information into a text area.

I'm able to get the username to show when they login but i cannot get the information area to show.

1

u/halfercode May 15 '20 edited May 15 '20

Guru99 looks rather poor, at least from a security perspective. They mention SQL Injection vulnerabilities on the PHP Security page, but don't mention that on the PHP Database page, and there is no mention of parameter binding that I can see. They suggest storing passwords uses MD5 and SHA1, which are both unsuited to the purpose, and they don't mention password salting at all.

1

u/Yamiik May 21 '20

hich are both unsuited to the purpose, and they don't mention password salting at all.

Is there anywhere else you would suggest? I'm currently using Laracasts, Still failing to create anything.

I think im trying to create something too big and not understanding how to start.

I created a fully functional (not secure) login/register page.

1

u/halfercode May 21 '20

I am not familiar with Laracasts, though I hear good things about it. However I would advise you not to jump into using a framework (yet) if you are wanting to learn the language.

Have you seen my blog tutorial? That might fit the bill - it does security properly, and doesn't use any external libraries or frameworks. It covers login, logout, sessions, safe database usage, and safe content rendering.

3

u/AdmiralAdama99 May 12 '20 edited May 12 '20

Theory + Practice = Mastery. Definitely get some practice in.

Google tutorials or simple projects you can do. Even something super simple like a form processor with form validation. Here is something simple to get you started. You can google and add to this.

<form method="post">
    <input type="text" name="username" />
    <input type="submit" />
</form>

<?php

if ( isset($_POST['username']) ) {
    $subject = $_POST['username'] . ' just signed up for your website!';
    mail('[email protected]', $subject, '');
    echo "<p>Thanks for signing up. The web master has been notified!</p>";
}

When you get more advanced, try coding some simple games. I made a chess engine in PHP for practice, but you could do something simpler like Tic Tac Toe. You can use HTML form elements such as check box to select the box, then submit to submit the move, then use PHP to keep track of the moves, check for wins/stalemates, etc.

2

u/eurosat7 May 12 '20

form is submitted via GET and not POST. That code will not work. ;-P

1

u/AdmiralAdama99 May 12 '20

Good catch. I will edit

1

u/mechanized01 May 13 '20

Dear, form can be submitted by both GET and POST method but it's better to use POST method for securing credentials. You can refer here : https://www.javatpoint.com/get-vs-post

1

u/eurosat7 May 13 '20

Better? Dig deeper and run into REST🤗

1

u/Astaltar May 12 '20

I think everyone had chess project, lol. I did platform to play chess between two players :) using long poling Ajax requests (websockets were not invented yet) I didn't have enough skills to develop chess AI ...

1

u/AdmiralAdama99 May 12 '20

I got my php legal move generation per node from like 2 seconds to 2 ms. After tons of optimization. I learned a lot from using xdebug and kcachegrind to optimize. But still too slow for a decent chess AI.

I made really well organized classes. ChessBoard, ChessMove, ChessPiece, ChessSquare, ChessRulebook. The next step to speed it up would be changing my ChessBoard data structure to something less readable. I didnt want to butcher my code, so I stopped there.

Was a super fun project. I learned a lot

3

u/AVeryLazyProgrammer May 12 '20

If your background is HTML/CSS it can be more effective to start learning Javascript first. As you are still struggling with basic programming concepts Javascript will not be any easier than PHP but you keep everything inside the browser with concepts you already understand.

1

u/paranoidparaboloid May 12 '20

So in most cases, PHP is going to be used for back end development.

What this means is that you're not going to see php do much tangeable work in the browser, and without that browser feedback it's difficult to work out why do things a certain way.

My reccomendation would be to follow some tutorials on Laravel. This will show you how to code in PHP, give an example of how an application can be organised, and let you quickly build pretty things. It can help you with basic web security, databases and html templating.

Enjoy!

2

u/AdmiralAdama99 May 12 '20

I think Laravel might be too advanced for somebody that is completely new to programming. Sounds like this individual is still at the "learn basic programming principles like if/else, for/while, variables, arrays" stage, and isn't ready for classes, frameworks, etc.

2

u/Yamiik May 12 '20

The thing is my brain is understanding if/else/ foreach, variables, arrays etc most of those concepts my issue is creating something from it.

I've even looked into classes and framework and can already see how quicker/cleaner it would make everything.

2

u/AdmiralAdama99 May 12 '20

Thats awesome. You are farther along than I thought then. Great job

1

u/paranoidparaboloid May 12 '20

You might be right.

I was thinking that the boilerplate being in there provides examples and proof of principle. and that they could start making small changes and watch the impact. That's how I learned PHP, but I grant you that I had OO fundamentals before that.

OP can decide, but should definitely take the above comment into account. It's a rabbit hole.

2

u/AdmiralAdama99 May 12 '20

I'm just thinking back to my first experiences with frameworks. I was well past the if/else stage, but I wasn't comfortable with composer, the command line, and using an ORM for my SQL queries yet. I also didn't want to learn a templating language from scratch when I could just use <?php if ( ): ?> statements. Ended up going with CodeIgniter 3.

I do see the awesomeness of Laravel and I will learn it soon. I read a lot of the Laravel documentation earlier today actually. Time to beef up my framework skills. But yeah, just not particularly beginner friendly.

2

u/paranoidparaboloid May 12 '20

Different strokes for different folks they say. It forced me to compartmentalise my code and to be atomic from very early on, which I think improved my development a lot. It also taught me security minimums etc. just from what is already there when you spin it up.

I get it though. It's learning to swim in the Mariana trench.

Yeah, I'd recommend if you're looking into Laravel to give it a go. The speed at which you can get a working system is mindblowing. You can have a structured, bootstrap styled, csrf secured, authenticated system inside a minute. It also ports quite nicely to modern js front ends. I've been working with it for a few years now and it is rarely painful.

2

u/ImMaaxYT May 12 '20

tl;dr: start small by dropping some PHP into your existing sites for simple tasks, then advance for some more tasks.

I started like you, only HTML and CSS.

Then, I learned JavaScript, but realized, that the frontend was very limited and simple things like view counters couldn't be realized with it (again, I was just starting out and had no concept of frontend/backend yet). So I asked people "how would I do something like a simple view counter?" and everyone told me to look into PHP for that.

Luckily, my free web host at that time supported PHP, so I just dropped a little PHP snippet into my existing website and boom - it worked! I had my own dynamic view counter on the page! I was endlessly amazed by that!

After some time, I looked more into PHP, because I wanted to discover what else is possible with it. The next thing I really did was automatically updating the copyright year and some veeeery simple templating.

Later, I took a look at forms to make an eMail contact form and my first login-only area.

Some time passed by and I eventually learned about the concept of MVC. That's where I got into OOP and wrote my first real libraries.

So, what do I want to tell you with all this info? Start small. Just drop in some PHP into your existing site, just for some small feature you found kinda cool on other sites. Repeat that process with some other nice features. Don't forget to try and understand what's happening in the snippets, though. That's important.

2

u/smo0f May 12 '20

Why are you learning PHP? Is it to create a form of some sort that saves data to a database? Then learn how to create a form, connect and read/write to a database. It's always good to first know what you want to do on a higher level, then break it down into smaller steps.

2

u/DesignatedDecoy May 12 '20

I'd recommend the laracasts php practitioner series. It's a free and Jeff Way creates some high quality content. This should be a decent introduction to modern php and if you find yourself interested at the end, his first series covering the basics of laravel is also free.

https://laracasts.com/series/php-for-beginners

2

u/ShaggyHotDog May 13 '20

That is what happens to almost all beginner. Start by making project. That's the way to learn things better. Atleast it helped me. Start with a todo list, or even simple app. You will slowly slowly start to get a hang of it.

1

u/eurosat7 May 12 '20 edited May 12 '20

Drop any article older than a year. There are some zombie articles out there.

There are also many tutorials out there by people what "share while they learn how to code somehow". This is NOT what you want. If it is by text or video does not matter. Material in textform tends to be better, because it's easier to correct - and you decide the tempo.

If code looks not pleasing to you - there is a chance it is bad code and your feeling is right. In this case ask somebody if it is good code. if not - leave it behind.

phptherightway might be overwhelming but is a good source.

1

u/__zaris May 12 '20

Make projects as you go. From each one you will gain something useful smth you didn't understand before. The more projects uou make, the better you'll understand the language friend :)

1

u/ryantxr Jul 16 '22

It’s a long journey. Start with something simple. Make sure you understand everything about your simple example. Think and some complexity to your example.

Challenge yourself. Set about making a program to do X. Then make your program do it.

Don’t try to learn too much too fast.

There are many PHP videos, screencasts and tutorials. Take advantage of them.