Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,833 members, 7,810,203 topics. Date: Friday, 26 April 2024 at 11:36 PM |
Nairaland Forum / Science/Technology / Webmasters / Tutorial-building Dynamic Websites (17998 Views)
Tutorial: Building A Facebook Chat With Jquery/php / Building Dynamic Websites (Harvard College) / Building Dynamic Websites With MySQL And PHP (2) (3) (4)
(1) (2) (3) (4) (5) (6) (Reply) (Go Down)
Re: Tutorial-building Dynamic Websites by Nobody: 9:44pm On Nov 12, 2008 |
and these
|
Re: Tutorial-building Dynamic Websites by Nobody: 10:13pm On Nov 12, 2008 |
Because the database has to be secured from all users (cos, it is possible to connect to a database from elsewhere, which we dont want) we will be creating a user account, i.e. username and password. The database will expect anyone connecting to it to supply a username and password so we will be creating one, By default MySQL has a user called root. this user has al previleges and all we need to do is create a password for this user Since this is for development only, will not give my DB a tough password, "pass" should do
|
Re: Tutorial-building Dynamic Websites by Nobody: 10:27pm On Nov 12, 2008 |
Thats it, go to the system tray and start apache, sure php should start with it
|
Re: Tutorial-building Dynamic Websites by Nobody: 10:50pm On Nov 12, 2008 |
Now, we will be faced with one process that could slow down our work, and that is opening folder and sub-folders until we get to the apache htdocs folder I hate this and i am sure you will too, over time so here is a trick create a desktop shortcut, so that way, when i double click the shortcut, it opens that folder for me and from there, it becomes fun. to create the shortcut, right click on an empty area on your desktop, select "new", "shortcut" fill the form and we are ready start coding but first, we need to tell apache to treat index.php files the same way it does treat index.html that will be for tommorrow
|
Re: Tutorial-building Dynamic Websites by kausikkumaar: 10:33am On Nov 13, 2008 |
Install WAMP or XAMPP which will be much more easier |
Re: Tutorial-building Dynamic Websites by Nobody: 8:36pm On Nov 13, 2008 |
Thanks sir, i personally use wamp, but it will be better to let people know how they all work first I am doing this because i found out that most people here on Nairaland whom we address as programmers dont even know they can indeed write their own applications without help from 3rd party scripts (not in all cases though) the hidden goal of this tutorial is to build a real web application developer and if you dont mind, let me continue |
Re: Tutorial-building Dynamic Websites by tweb1: 9:27pm On Nov 13, 2008 |
These procedures are they the same for all versions of Apache, PHP nad mysql? |
Re: Tutorial-building Dynamic Websites by quadrillio(m): 3:28pm On Nov 14, 2008 |
I've started a tread similar to these https://www.nairaland.com/nigeria/topic-193865.0.html#msg3086749 Am planning to join with you just in case may help is need or I should continue with mine Fellow Nairalander & @ poster what is your opinion. |
Re: Tutorial-building Dynamic Websites by MT: 5:09pm On Nov 14, 2008 |
@quadrillo, I strongly suggest that you still continue with your thread separately, so that at the end of the day, it will be like nairalanders are having 2 different "classrooms" that complement each other. If I dont get a particular explanation right in one thread, I can go the other thread and get it sorted out. I'm happy about your attitude to help without being paid. May God bless you and webdezzi |
Re: Tutorial-building Dynamic Websites by MT: 6:49pm On Nov 16, 2008 |
@webdezzi, May I ask that you try as much as possible to make out time for us , "your students", out of your busy schedules. I sense it seems the enthusiasm is waning. |
Re: Tutorial-building Dynamic Websites by Nobody: 9:04pm On Nov 16, 2008 |
I am working on a project and also moving my files around as i just got a new laptop, thats why, I will still make time out. and thank Quad, you can contribute |
Re: Tutorial-building Dynamic Websites by tweb1: 9:01pm On Nov 18, 2008 |
@webdezzi When will the holidays be over? when are we going back to PHP class? or have you decided to take us only half way? Your were good though, |
Re: Tutorial-building Dynamic Websites by Nobody: 8:45pm On Nov 19, 2008 |
I am trapped in a BRT hold up, since i can't do much work, i think I will be able to move on from where we stopped lets see what you must have before you proceed with us Apache installed php installed mysql installed and a file inside our Program Files > Apache Software Foundation > Apache2.2 > htdocs > tutorial folder named index.html Now we need to rename index.html file to index.php because we want to test to see if php has been configured correctly after renaming it, go to the address bar and type http://localhost/tutorial hit enter and you should see something that looks like the image below That is a list of what we have in the tutorial folder and thats because Apache can not find an index file so we need to inform apache about a new tenant that just moved in -PHP (at least he deserves the same right as html) every time apache starts, it reads the content of a configuration file to know how he is supposed to behave so we will just open that file and edit it. Next, we will be editing the apache config file and that will be tommorrow. Good night.
|
Re: Tutorial-building Dynamic Websites by Nobody: 11:08pm On Nov 20, 2008 |
(Dont forget that we are still going to test to see if php has been configured correctly) I will use this part to try to expose how your mind should work when programming your way to being a grand master (i will assume, i am new to apache) I will navigate to the apache folder, Why? Because apache is the one serving our pages and we need to tell him to serve index.php whenever a user request for a directory like http://localhost/tutorial so i navigate to Program Files > Apache Software Foundation >Apache2.2 so am lost, where do i go from here, i see the following folders: bin, cgi-bin, conf (wait, something tells me, conf is short for configuration, let me open that first) i opened the folder up, but the files in it has funny names and looked like files not meant to be edited, but there is a file that says httpd.txt (image 1 below) maybe that's it, let me have a look. yes! thats it. but how do i know what and what to change Lets use logic here, since apache is already serving index.html files as the default file, i can guess that this httpd.txt file contains the word index.html, so if i can find index.html, then i have hit it it is my style to use the "find" in image 2 below (i will let the computer do the search, while i just look) good, i found an index.html in image 3 below, (i know your mind should be telling you to replace it with index.php, but is it not possible to append index.php to index.html so that .html can still be served if .php is absent) but how do i append it, is it a comma, or space or on a new line let me google for this text that surrounds the index.html, someone must have asked such question on a forum elsewhere and probably gotten answers <ifmodule dir_module> directoryindex (dont worry, google is not case sentitive) now i found many results, and from the first 5, i can see that it has to be space, so i just add index.php like we have in image 4 below save it and restart my apache COOL! it works, it appears, apache now serves index.php as my directory index file so we can see our first website now create a test.php file and save it inside the tutorial folder with this little code in it <?php echo "PHP is working";?> now go to http://localhost/tutorial/test.php and you should see this PHP is working (without those tags) The <?php echo " ";?> part of the code helps to instruct php on what to do. if you see the code the same way you typed it in, then check the code again or copy and paste this directly from here else you will need to start with your php installation again, as you probably missed something out That will be all for today Tomorrow, we will download phpmyadmin phpmyadmin(short for php-mysql-administrator) is a tool built with php, created just for managing mysql database and has won several awards online, it allows you to do almost anything with mysql without having to read the mysql manual and we will download it and put it in our web server folder, so we will access it from here http://localhost/phpmyadmin
|
Re: Tutorial-building Dynamic Websites by Nobody: 7:17am On Nov 25, 2008 |
I am sure by now, you must have google for the phpmyadmin tool and downloaded it (thats if you are curious) If not, Then go to http://sourceforge.net/project/downloading.php?groupname=phpmyadmin&filename=phpMyAdmin-3.0.1.1-english.zip&use_mirror=dfn thats the link. download that file and unzip it into the htdocs folder, It comes with a weird folder name like phpMyAdmin-3.0.1.1-english just rename the folder to phpmyadmin (for convenience, so we don't need to bother about the version) and make sure it is in the htdocs folder so go to http://localhost/phpmyadmin you will run into a small problem on that page on my page, it says phpmyadmin error can not load mysql extension please check your php configuration -documentation thats ok, we are getting that error because we did not install the mysql extension An extension is a small program that depends on a main program to function For an extension problem like this, i will go to google and search for "phpmyadmin error can not load mysql extension please check your php configuration" this is a challenge for you, try to figure things out yourself, by using google as a place to go for help while trying to solve this problem, you will end up learning some tips and tricks you probably wouldn't have known. if at the end, you still can't get phpmyadmin to work, then come here and post the problem so we solve it together. for now, let us proceed. |
Re: Tutorial-building Dynamic Websites by Nobody: 7:52am On Nov 25, 2008 |
now, we will be looking at other ways we can setup a HTTP server, PHP, Mysql without going through all these boring steps. situations may arise when you may need to move you project from one computer to another,certainly, we dont want to go through all the pain. Now thanks to some good guys out there who have spared some of their precious time to write a single program that will install all these 3 guys for u, with just a few clicks. examples of such software includes wamp-stands for windows Apache Mysql and PHP you can get it from here- http://www.wampserver.com/en/index.php (thats the english version) XAMPP is another option if you are into perl programming, it works for php too X means cross platform, Apache, Mysql, PHP and perl there are loads of such softwares online but i prefer wampserver. THIS IS FOR THOSE WHO WILL NOT LIKE TO GO THROUGH ALL THOSE HEADACHES(i mean, whats the point in breaking through a wall that has a door, lets use the door o jare) so go get your wampserver installed and we move straight to business. after the installation, you will end up with a folder "wamp" on your C drive so your htdocs folder becomes www so you will have to move the tutorial folder into this directory C:\wamp\www i expect you to uninstall all previous installations so you dont run into problems, although those installation can still live together with wamp, i will advice you uninstall them or stop their services from running. please back up your project file first, i mean the tutorial folder If you dont know how to uninstall a program, go to start> control panel>add or remove program(on vista, it is programs and features,(i hate microsoft for this)) >select apache, unistall it, mysql, unistall it, php, unistall it restart your system, then install wampserver and restore your tutorial folder to the C:\wamp\www and we are ready to go, 1 cool thing about wamp is that it also has phpmyadmin built in. Now lets look at some basics of php programming |
Re: Tutorial-building Dynamic Websites by Nobody: 9:09am On Nov 25, 2008 |
PHP stands for Hypertext Pre-Processor (just wondering why they did not call it hpp, anyway, the manual explains it) what php does is process our script before spitting out the output. there is no way you will be able to view php codes in a web page's source you will only see the result of the php code, which most times, are html, css, javascript php is a server side language, it resides on the server, and stays there forever, you wont get to see the underlying code html, css, javascript can well be call client side languages cos you can read them on your client side(the browser) right click an empty area of a web page and view source (it may vary across browsers though) that code you see is what your browser got from the server and does not contain any server side code. any file ending with .php is passed over to the php engine for processing like we discussed earlier and php on its end, looks inside the file and tries to parse it php does not parse all the content of a file it simply looks out for what belongs to him, parse it and leaves the rest like this short php code
let us break this down <?php - this informs php engine to get ready, this is the beginning of a php code ?> -informs php engine to stop processing the script. this is the end of a php script so your code must begin and end with these 2 opener and closer if you look above <br/> belongs to the html family so the php engine will not run that, it will leave it as it is the last line will be run by the php engine so the output to the browser will be this is the first linenotice that there is no space or new line in the output It is now the job of your web browser to interprete the html part of the code i.e <br/> so what you get displayed in the brower will be this is the first line while the source code will be this is the first line now let us break this down echo "this is the first line"; echo is a language construct in php, if you use that in your code, you are simply telling php to output whatever follow, so that the web browser can see it notice the "" surrounding the output, it is a way of representing the type of text involved for instance, this is a first line is of the type string - string is a series of character or text other types includes int meaning integer Boolean meaning true or false, 1 or 0 float meaning decimals arrays - this is more of name-value pairs stored together, e.g (lagos-fashola, nigeria-yaradua, keyboard-fingers, leg-shoes) the ";" is what tells php, this is the end of a statement and you must include it at teh end of all your statements Now lets see what we can do tomorrow |
Re: Tutorial-building Dynamic Websites by Nobody: 9:33pm On Nov 27, 2008 |
we will be getting into more depth on what all those syntax mean as we move on, if there is a syntax you dont understand, please let me know. no trick here, all will be doing is creating a page that will insert record into our database(thats the admin area) and a page that will display the content. first we need to build the database, to build the database we need to know what type of data we will be storing. we will be storing the following 1. the news headline 2. the main story 3. the date the news was posted 4. Name of who submitted the news 5. an additional identifier, this must have a unique attribute(i will tell you why briefly) lets say we want to delete a particular news, it will be bad practice to delete a news by its headline |
Re: Tutorial-building Dynamic Websites by RuuDie(m): 2:39pm On Dec 12, 2008 |
Aaawww. . . . . absolutely stupendous guys - WELL DONE! Pls lets try 2 keep the thread out there so that peeps can easily locate! |
Re: Tutorial-building Dynamic Websites by RuuDie(m): 2:43pm On Dec 12, 2008 |
Is all these possible in VISTA |
Re: Tutorial-building Dynamic Websites by RuuDie(m): 2:49pm On Dec 12, 2008 |
@ webdezzzi, abeg big bros. . . . . how i go fit contact you for a one-on-one tete-a-tete |
Re: Tutorial-building Dynamic Websites by Nobody: 4:08am On Dec 16, 2008 |
@Ruudie, Maybe next year on 08029037890 and yes. it's all the same windows, just a little beautification by microsoft I have been away working on projects here and there, I also took the time to change the look of my website. I decided to put a temporary new look to my site The real concept i had in mind is on its way, Back to where we are, since we will be storing 5 different data everytime we post a news from the admin area, let us write an SQL for for that SQL stands for Structured Query Language, This is the only language used by all database applications and this language is similar except for little difference across the different databases we have. To write our SQL, i wont take you through the coding. We will use phpmyadmin which came with WAMP. this tool lets you see the underlying SQL Note that phpmyadmin is not the database, it is a tool that interfaces with the database, you can also write sql queries using CLI (command line interface or better still in everyone's language, command promt). all phpmyadmin is doing for us is generate the sql based on our selections and giving it to mysql. 1. i made the database name tut99 (a little security here and there matters) 2. you can see the drop down showing on which database we are currently working on and the database name showing that we have zero number of tables although phpmyadmin created the database for us, we can still see the query and that way, you learn the underlying sql if u want to since we have no table, you can see phpmyadmin asking us to create one 3. I named my table m_new, at least thats a bit difficult to guess (another added security, my preference though) 4. Here we need to decide what we want and give it to phpmyadmin first we have 5 fields, the first will be the ID we talked about and values inserted into this column has to be unique so we need to select unique, because we don't want to startchecking if a value exist in that column all the time, we will add an auto_increment attribute to it. That way, the database will will automatically increment this column by 1 (if the last entry was 7, the next will automatically be set to 8 ) so we don't need to insert any value to this column, it will be done "miraculously" the type has to be int, short for integer, and i named mine id, which is not a must, you can give it any name you like second field will be holding all headlines, we will use varchar type which wont take character over 255, third, the story may be as long as an epistle, lets use text for that, a text type will allow us insert almost unlimited number of character while allowing us to preview the first few line from phpmyadmin, note that we can also use blob-meant for binary data e.g picture, .exe software but preview may be difficult from phpmyadmin. for the date, we will use DATETIME, this expects us to submit the date and time in this format "2008-12-16 03:50:34" anything other than that will force mysql to store 0000-00-00 00:00:00 instead 5. the person who posted the news, i will make it varchar (even if your name is longer that Mahershalahashbath, it will still make it into that column without being truncated) if your selection is wrong, phpmyadmin will take you back for correction e.g adding auto increment to a column of type:varchar this is the code i got from create the table CREATE TABLE `tut99`.`m_news` ( i can run this code from anywhere that allows me to connect to mysql i can run it from my php script, CLI, phpmyadmin, python program, or name it
|
Re: Tutorial-building Dynamic Websites by OmniPotens(m): 2:12am On Dec 19, 2008 |
@webdezzi Keep it up here man. I hope you're pals out here are learning and not just reading. You should ask them questions from time- to- time to make sure that they are catching up with the tutorials in here. Cheers! |
Re: Tutorial-building Dynamic Websites by Nobody: 10:38am On Dec 21, 2008 |
Thanks, I expect questions incases they are not getting any part of it. |
Re: Tutorial-building Dynamic Websites by jmslimx(m): 12:58pm On Dec 21, 2008 |
nice one , i wish i could see some .NET geeks do same here men, because i am tryin 2 move on 2 it need some fundamental |
Re: Tutorial-building Dynamic Websites by OmniPotens(m): 3:20pm On Dec 21, 2008 |
jmslimx: Try switch between here and the programmers section. Both ways, you'll get at what you want. Cheers! |
Re: Tutorial-building Dynamic Websites by Nobody: 10:07pm On Dec 23, 2008 |
As a rule, i dont usually answer any question related to a different topic from what we are talking about, i double between programming and web designing, this will not be for instance a good place to start talking about .NET, the subject at hand is PHP/DHTML i think! |
Re: Tutorial-building Dynamic Websites by Nobody: 2:54pm On Jan 04, 2009 |
**************************Happy New Year*********************** to all, I must say i took my time to enjoy the just concluded holiday and had to forget this thread but not you guys. Lets continue from where we stopped. |
Re: Tutorial-building Dynamic Websites by OmniPotens(m): 3:11pm On Jan 04, 2009 |
@webdeaai Welcome back. I hope you really enjoyed yourself. How is the new year going to be like? You are welcome back and full time, back to work. Continue your thread as you can see it is on top of the section now |
Re: Tutorial-building Dynamic Websites by Nobody: 3:44pm On Jan 04, 2009 |
Thanks Omni, I believe that we have our database setup already and next, lets open up our Notepad++ and navigate to the index file in our tutorial folder. lets open the file up and see what we have to do. (i will advise that you open up your web browser, point it to http://localhost/tutorial so you can preview changes easily) we need to point that link to a page that will display the news, so we need an extra page for that, Lets duplicate the index.php file and rename the duplicated copy to "readNews.php"
now we should have 2 file inside the tutorial folder, index.php and readnews.php we already have our index.php file opened in notepad++, lets point the link that says <a href="#"><strong>Click here to get news update</strong></a to <a href="readNews.php"><strong>Click here to get news update</strong></a we changed the href from # to readNews.php, save it and refresh the browser you opened. when you now click on the link, it should take you to readNews.php page which displays pretty much the same thing because we duplicated the page and we are yet to modify it. Now go ahead and open up readNews.php by going to File> open (you will notice that notepad++ will open the last directory you visited) MAKE SURE YOU OPEN IT FROM THE SAME NOTEPAD++ INTERFACE this will go ahead and open it up in another tab, just like firefox does. that way, you are able to swap the interface/workarea to different pages at anytime |
Re: Tutorial-building Dynamic Websites by Nobody: 4:51pm On Jan 04, 2009 |
@webdezzi (m) great job man - u do not wear a !hash bang for nothing - i have not read your thread properly - but what i have seen so far - i am more than impressed, keep up the good job - i will link to this thread from mine - i dont have much patience in teaching php - i prefer to just pick a little topic and discuss it thoroughly and then leave space for questions - i just cleared up an ajax-based chat and also image verification captchas - in 2 short thread and even posted samples and free downloads - that way my conscience is clear (if the codes are too long to follow) - but i will answer questions from the students though. |
Re: Tutorial-building Dynamic Websites by Nobody: 5:28pm On Jan 04, 2009 |
Thanks Dhtml for dropping by. The goal of the readNews.php page will be to fetch news from the database and display it. even though we have no news in our database right now, we can still code it to display news then we will insert news later on the first thing we might want to do is connect to our database and php has it's way of connecting, mysql_pconnect ( "server" , "username" , "password " ); (opens a persistent connection, so the connection remains opened throughout the script) mysql_connect ( "server" , "username" , "password " ); (opens a non-persistent connection) any of this will work but i prefer to use the one with pconnect our server will always be localhost, even when you upload your website to the web. (if your mysql server is running on another computer, then your server will be that computer's IP address or domain name) the username will be the username of the user allowed to connect to the database the password will also be the corresponding password to that username. It looks cool, right? Now let us assign that connection to a variable, so next time we need to use that resource (the connection resource), we just use the variable we are about to assign it to $conn=mysql_pconnect ( "localhost" , "root" , "" ); // right now i have no password set to my database, if you have it set up for yours, then go ahead and use it since we will be using this line on more than one page, we will go ahead and put that line in another file, then we will just include it in any of our script that requires connecting to the database. That way, we only have to change content of the newly created file and it updates throughout our script Lets create another file, this time, lets call it conn.php and put this line of code in it From now on, i will be adding comment to the codes as it is good programming practice
<?php ";" the semicolon sign must end every statement in php, else, you will get a syntax error, unexpected T_INCLUDE, expecting ',' or ';' you dont have to bother about what a statement is and what a statement isn't, just take note of when i use ";", before you know it you will get it naturally. curly braces "{" and "}" in php help with handling conditions, example this is similar to a mother breastfeeding her baby, if (the baby's head is closest to the right) {the baby gets the right breast;} else {the baby gets the left breast;} another situation could be when you have a loop, curly braces also works there while (the music is rolling){we keep dancing;} what this means is, if the music does not stop, we will not stop dancing (even if it rolls for 3 years). once the music stops , then we stop dancing thats just by the way, Now we continue tommorrow by including the coon.php file into our readNews.php so that we can fetch content from our database. bye for now, and please ask questions when confused. |
(1) (2) (3) (4) (5) (6) (Reply)
How To Transfer Data From S3/S4/S5/S6 To S7 Edge / Facebook Owner Mark Zuckerberg Reacts To President Trump Policy. / Learn The Domain Name Business - See What Sold, See What Just Dropped
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 100 |