On today's tutorial we will talk about creating a blog on php and mysql
Table of contest:
1. Connecting to mysql database
2. Creating mysql tables
3. Coding the blog
Download
Connecting to mysql database is simple, in just few lines of code
Before we start i suggest you read Php Mysql posting to database for better understanding of mysql.
<?php
// connecting to host
mysql_connect("host", "user", "password"); // replace this with your data
mysql_select_db("your_database"); // database name here
?>
Creating database, tables and columns
Now let's build the mysql table.
First build a database if you haven't, and dont forget to edit the connection details at the top.
Click on databases
Set a name to it and click create.
Now we must build the tables:
Click 'go', a new table will popup, complete those fields like in the pocture below:
Scroll down and click save.
Last one, click on posts and insert tab at top, write something to title, and id live empty.
Now lets continue coding the blog
// connecting to host
mysql_connect("host", "user", "password"); // replace this with your data
mysql_select_db("your_database"); // database name here
// lets build a blog
if(isset($_GET['post'])){
$post = $_GET['post'];
// first of all we will check string length
if(strlen($post) > 11){ // if post id is bigger than 11 charachters
die('Blog post nof found.');
}
// now we will make sure that the post id is numeric and this is a nice security method
if(is_numeric($post)){ // is numeric allows numbers only
$post = (int)$post; // and the int function, which replace every
// string to its correspoing number
// for the tutorial im gonna add mysql_real_escape_string
// but is not really needed in this case
$post = mysql_real_escape_string($post); // final sqli defense
// final part
$query = mysql_query("SELECT title FROM posts WHERE id=$post LIMIT 1");
while($row = mysql_fetch_array($query)){
echo $row['title'];
}
}
else{ // if post is not numeric then
die('Blog post nof found.'); // post does not exist
}
}
else{
// if post is not submitted display them all
$query = mysql_query("SELECT title, id FROM posts");
while($row = mysql_fetch_array($query)){
echo $row['title'];
echo $row['id'];
echo '<a href="?post='.$id.'">'.$title.'</a><br>';
}
}
?> Few last tips!
I used LIMIT 1 on the first mysql query.
That's done for 2 main pruposes:
1. we are only displaying 1 result
2. it's a nice speed optinization for mysql
To display blog posts by newest ones replace
SELECT title, id FROM posts
with
SELECT title, id FROM posts ORDER BY id DESC
It's a simple blog who does the work.
If you want to learn more about sql injection we suggest Sql Injection prevention tutorial
Excellent blog very nice and unique information related to Php Mysql blog tutorial. Thanks for sharing this information.
ReplyDeleteSEO courses
Great Job, Keep It up!!!!
DeleteWas having some trouble understand how to pull the information from the DB and show its result, but after reading your tutorial i have a complete understanding of it now, great commenting. Thanks!
ReplyDeleteCreating Experts
Deletephp Training in chennai
Creating Experts provide Real Time scenarios php training in Chennai.At creating experts the trainers have around 8+ years of experience.They teach the advance level topics by giving real time examples.
Contact us: 8122241286, 9003085882 – Karthick
Here everything is practical basis not any classroom training.The trainers are working in mnc's and they will take classes only on Saturday and Sunday.
Contact us : 8122241286, 9003085882 – Karthick
Ref Link: http://thecreatingexperts.com/php-training-in-chennai/
Excelente el blog tanto la info como el diseño y la estetica del mismo, lo estoy poniendo entre mis favoritos, saludos cordiales.-
ReplyDeleteNice
ReplyDeleteHi there. PHP mysql is the growing trend now. It is a quite nice post PHP professionals. Thanks for sharing it.
ReplyDeleteAwesome post for Freshers and PHP professionals those who are in search of job or someone working in Non IT sector and desire to extend their skill sets to be a PHP Web Developer.
ReplyDeleteThanks for sharing appropriate info.
wow now i understood it very well. thank you
ReplyDeleteGood to know @Jiten :)
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteI am really glad I've found this information. Nowadays bloggers publish only about gossips and net and this is really irritating. A good blog with interesting content, this is what I need. Thank you
ReplyDeletethat was grt
ReplyDeleteHI, for some reason i get the following error. Can you help please|
ReplyDelete( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wampXXXXXXXXXXXXXXXXXXXX (deleted sorry!)
Call Stack
# Time Memory Function Location
1 0.0015 371600 {main}( ) ..\newblog08052013.php:0
2 0.0364 388776 mysql_fetch_array ( ) ..\newblog08052013.php:37
Did you follow all the steps correctly?
Deletethat was great tnx very much :)))))))))
ReplyDeleteThanks a lot.Through this post I learned lot of new things to create my new blog.
ReplyDeleteI can see that you are are genuinely passionate about this! I am trying to build my own website and youve helped me with some great
ReplyDeleteinformation.
http://www.sqlservermasters.com/
Thanks :)
ReplyDeletecan you tell me where to find mysql 5.6 developer(1Z0-882) exam in PDF/VCE??
DeleteThanks:D
I need to know XML concept,,Could you explain it?
ReplyDeletebest dissertation topics
hjh
DeleteThe tutorial is best suited for Freshers who are in search of job or someone working in Non IT sector and desire to extend their skill sets to be a PHP Web Developer. This tutorial is also suited for people who want to migrate from other scripting languages like asp.net, cold fusion, perl, jsp to the rewarding world of PHP 5 and Zend Framework.
ReplyDeleteThanks for sharing.
Learnpact
pls provide...platforms for others to blog also
ReplyDeleteNice post. I usually use PDO to avoid SQL injection.
ReplyDeleteThank for sharing nice tutorial of creating blog using php and Mysql. It is very helpful to us.
ReplyDeleteHi..i appreciates your blog post, your detailed specification and steps are very helpful for us to make our own blog at free of cost. Thanks for haring this features with us.
ReplyDeleteNice blog post! But if you are newbie to mysql then you should learn Basics of MySQL and PHP communication in detail. Thank you.
ReplyDeleteKind Regards,
Sahil Sharma
www.webdevelopersahil.com
hi i have the actual problem, when i click to a post , give me this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/CCCCC/public_html/index.php on line 84 Line 84 is // final part
ReplyDelete$query = mysql_query("SELECT title, FROM posts WHERE id=$post LIMIT 1");
while($row = mysql_fetch_array($query)){
echo $row['title'];
}
please help!
it is really a worthy one and all the points in the above blog were very useful, freshers for blogging would find it useful and really it would be useful for them.
ReplyDeletethank you
with regards,
krishna
Good information for me. please keep updating us with new posts. thank you so much .
ReplyDeleteThis blog is very informative for me please keep it up. Empowerment Technology
ReplyDeletefor more programming tutorial visit http://www.9code.in
ReplyDeleteIts one of my favorite PHP tutorial blogs and more insightful information.It fulfill my needs too.
ReplyDeleteThat's great..
ReplyDeletethanks for sharing an awesome php tutorial for all beginners..
ReplyDeleteIts really helpful for me to understand where we i lost in my previous interview. Thanks.
ReplyDeleteIf anyone wants to Learn oracle in Chennai go to the Besant Technologies which is No.1 Training Institute in Chennai
http://www.oracletraininginchennai.in
I got a job by saying this answer in my last interview. thanks for awesome help.
ReplyDeleteI got more idea about Oracle from Besant Technologies. If anyone wants to get oracle Training in Chennai visit Besant Technologies.
http://www.oracletraininginchennai.in
aaa
ReplyDeletehttp://matrixnmedia-staging.com/common/fb_responsive/
ReplyDeleteUsing PDO in PHP on Mysql coding makes itsecured.
ReplyDeleteNice Post!
ReplyDeleteBeing a novice in coding how can I implement this one in one simple html website? Can anyone point me some realistic directions?
ReplyDeletenice
ReplyDeleteGreat Post... Hope it would be helpful for Web Developer..
ReplyDeletewebline infosoft - Dehradun is also helpful for designing and development the website.
such a nice and useful information, i request to please keep it up this blog
ReplyDeleteGood post Mikel, it's always good to see developers helping others and by the looks of it lots of people have found this really useful. Thanks for sharing :)
ReplyDeleteI am searching an article for like this,finally I reached your blog. I feel this is a Very good post! Keep up the great writing.
ReplyDeleteOnline Booking system
ggg
ReplyDeleteThanks for sharing.
ReplyDeleteI have read your Article very useful for python programming.They are site is very useful clearing the errors of python programming.Thank you for sharing you information.Python Training in Chennai
ReplyDeleteThanks for this great post! It has been very helpful for my site zachariahlarsen.com
ReplyDeleteI like your blog post and helpful for me make connection thanks for share How to connect MySQL Database in Php with easy Steps
ReplyDeleteHello,
ReplyDeleteif you guyz need to create some basic validation and logics to process a long html form,check out this.. www.kodebuilder.com
Good set...
ReplyDeleteMysql Interview Questions and Answers
I can't send my answer to the MySQLexam, Why??
Deletenice
ReplyDeleteGood collection..
ReplyDeleteMysql Interview Questions and Answers
I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs.
ReplyDeleteStarbucks Story of Growth Case Solution
Really this is very informative blog if anyone looking for learn php then we provided PHP Tutorial this is free online tutorial
ReplyDeleteFree Online Classified | Post Ad | US Classifieds - mukru.com usa no. 1 largest marketplace to buy, sell, find used product, servicees in your local area.
ReplyDeletehttp://www.mukru.com
it was gd
ReplyDeleteThis article is really awesome. It enjoys me very much. The content are so much informative.Thank you writer for giving me such a good article. SeoDevil15
ReplyDeleteYou’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.Seo BaclinksSocial Bookmarking And Backlinks Service.
ReplyDeleteHire PHP developers from a skilled and experienced PHP web development company which provides excellent PHP development services.
ReplyDeletezxzx
DeleteCreating Experts
ReplyDeletephp Training in chennai
Creating Experts provide Real Time scenarios php training in Chennai.At creating experts the trainers have around 8+ years of experience.They teach the advance level topics by giving real time examples.
Contact us: 8122241286, 9003085882 – Karthick
Here everything is practical basis not any classroom training.The trainers are working in mnc's and they will take classes only on Saturday and Sunday.
Contact us : 8122241286, 9003085882 – Karthick
Ref Link: http://thecreatingexperts.com/php-training-in-chennai/
Thanks for the great information in your blog PHP Training in Chennai
ReplyDeletewhat is the blog script
ReplyDeletehi
ReplyDeleteCodelobster is a very good free PHP IDE
ReplyDeleteThanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about php
ReplyDeleteThanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about
ReplyDeletephp
This blog is not only very interesting but also very informative. i never knew that bloggers do have a task to handle, please do keep up with the great work.
ReplyDeleteresume writing services
Great discussion and inform on where is web design going in 2016. Each and every year web design is growing and plenty of innovative and impressive things are shared and published every day.e-commerce web designs
ReplyDeleteWonderful article. This will be really useful for beginners, and I like how you've lucidly explained the flow with screenshots. On behalf of http://phpprojects.org, thanks!
ReplyDeletePls i need a blog for my set of Novices brothers... but im struggling to create one... i don't need a host.. i need a simple but good and free one... i would really appreciate you help me create one.. you could create a new email and link to my email androvishberrian@gmail.com
ReplyDeleteUhmmm... some info are: Don Formation House Ondo - Nigeria... the name for the blog sdbdream... thanks
ReplyDelete