AJAX - Comment Box with [ Javascript jQuery JSON PHP MySQL ] - Step by Step How to Guide - Part 6

preview_player
Показать описание
In this video we start to do a bit of house keeping and clean the code up, so as that the html file is not full of data.

Basically we use the php require_once function to extract the comment box data and then place it in a seperate file.

This data is then inserted using php. It means also that we do not have to have repetative code within our file.

If you dont understand this part, then dont worry as we will explain it further on the tutorials. Also I have many other videos that explain sections of the code which we have done. I would advise watching some other videos to be able to understand the php as little better.

If you are new to php, then its always going to be hard in the beginning, dont panic, every one has the same problems.

I also introduce you to the other php build in function of define, here we define folder locations in one constant, this helps you out later if you decide to change where the files are keep. Once you have changed the file location all you then have to do is to change the constant once and all of the other variables will still work. If you do not use this method, then you can find yourself searching through every file changing any require_once path to be correct once again.

PHP is about using business logic and keeping the code as flexible as possible although at the same time robust.

Have fun.
Рекомендации по теме
Комментарии
Автор

a nice way of using includes file, thank you for those tutorials!

nightkiller
Автор

Stating the full path to DOCUMENT_ROOT (includes folder and defines.php file) saved my tutorial #6 (an awesome tutorial which I almost gave up on). Without some tweaking, I would have given up 2 hours ago. Just know that it works! Adjusting the path (relative to full did it for me). Windows, Notepad++, XAMPP, and Firefox.

Looking foreword to continuing with it...

charleslahaie
Автор

Just want to share to people who got stuck with the php part. I am using dreamweaver with wamp. In the defines.php file you just have to write the same thing as seen in the video. In your index.php file at the top write this code: <?php Under the <ul class="comments-holder-ul"> write this code: <?php require_once 'INCLUDES'. '/comment_box.php';?>. That should work.

simbimbambum
Автор

When adding the echo I don't get the directory showen in the top of the page as shown at 3:40 and not that error message as well even though I've done exactly the same at that point. When I then keep following along I got no result at all, nothing is showing.

xXSomethingXx
Автор

gosh i just stuck at here, i had type excatly what you type on 3:36 but it just came out "Undefined index: DOCUMENT_ROOT what should i do ??

popoj
Автор

i got an error on placing <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/defines.php'; ?>

icepickero
Автор

you know this is very disturbing after all of this now its gone and nothing works :( i tried so hard to do exactly the same and still doesnt work at all after this video :( i dont think ill continue your other videos if you dont fix this !

Archzed
Автор

the defines part was unecessary, it's just your prefered method and it's destroying the whole thing for most people. If you're not confortable with this level of programming, simply type in the path like this:

require_once 'folder/comments.php'

If comments.php is in the same folder as the file your working on then all you need is:

require_once 'comments.php'

Excelsus
Автор

I was doing good with the css until the php started now my index.php is just showing plain text php.This shit aint easy to learn but drives me nuts to get it done.

TheDeniTV
Автор

These videos are great, thanks for putting the time in to share and teach.
One question.
Because I have a a bunch of directories/ projects in my servers root directory( and this project is in the ajax2 directory)  in defines .php i defined the doc root as define('DOC_ROOT', $_SERVER['DOCUMENT_ROOT'] . "/ajax2/");
it works, but is this a bad idea?

aarontaylor
Автор

this one is totally ununderstanding sorry for that but it is true

nuadaable
Автор

Can u make a tutorial about how to make a website with a main file in php, because since this step i've been making the comments boxes with a main page in html, but now I've realized that we need a php main page, but when I load the page in php instead in html I dont see the page with the comments, but i see the code on the browser page, and I've been trying to make the webpage with netbean, but the browser doesn't recognise the project! can you hel me please?

xXsharingan
Автор

Hi Sir, this tutorial was great. I love it! I am Just want to asking about some code that i was stuck on this tutorial. I wish you can help me.

* First i was fix the problem by my self about people asking on this box comment and i changes to be like this:

<div class="wrapper">
<div class="page-data">
Page data is in here
</div>
<div class="comment-wrapper">
<h3 class="comment-title">user

<ul class="comments-holder-ul">
<?php $comments = array( "a", "b", "c", "d"); ?>
<?php require_once 'INCLUDES' . '/comment_box.php' ; ?>
</ul>

</div>
</div>
<?div>

* Second thing i was try to put PHP code in "comment_box.php" from this code (it was from your tutorial actually):

<?php foreach($comments as $key => $comment) ; ?>

and then i am trying to close it with the code from your tutorial but its not working, the code was:

<?php endforeach ; ?>


Did you have other solution or maybe code to fix this? because when i trying to have a look on the browser the it said:

"Parse error : syntax error, unexpected 'endforeach' (T_ENDFOREACH) in : on line 44

Please I need your help, or maybe somebody can help me also to fix this. thank you so much!

note: i am using Adobe Dreamweaver to doing this. cherrs!

andrewsubastian
Автор

Everything works perfect except one thing. When I'm trying to change wrapper's height into auto nothing happens. I'm trying to add comment box on my videos page. I already have ready html page, just adding comments, may be this is the problem... Thanks for help in advance.

milam
Автор

how does it work with Dreamweaver wampserver? because Document_root doesn't work.
 

samha
Автор

sir i created an website using html/css but i am unable to create comment box, i saw your tutorial, i was ok upto tutorial 5, from tutorial 6 i am unable to execute, can you suggest me in creating php file and js file

sudharshans
Автор

I'm stuck in the same location too!! Somehow it can't detect my defines.php. Any idea how can i fix this?

dalatflyingallover
Автор

<?php require_once ('comment_box.php')?>  line 22

TouseefAkhtar
Автор

please help i want to learn how to fix this please

icepickero
Автор

it just wont work! when i insert <?php require $_SERVER['DOCUMENT_ROOT'] . 'defines.php'; ?> it keeps giving me errors and wont work and if I add <?php require_once('defines.php'); ?> that wont work either it just shows me one of my posts out of two that is with MORE button gone..

fadymikhaiel
visit shbcf.ru