Home » , , » Php Mysql blog tutorial, creating a simple and secured blog

Php Mysql blog tutorial, creating a simple and secured blog

php mysql blog

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
php mysql blog
Set a name to it and click create.
Now we must build the tables:
mysql create 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

<?php
// 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

83 תגובות:

  1. Really like that you are providing such information on PHP MYSQl with JAVASCRIPT ,being enrolled at http://www.wiziq.com/course/5871-php-mysql-with-basic-javascript-integrated-course i really thank you for providing such information it was helpful.

    ReplyDelete
    Replies
    1. Creating Experts

      php 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/

      Delete
  2. Excellent blog very nice and unique information related to Php Mysql blog tutorial. Thanks for sharing this information.

    SEO courses

    ReplyDelete
  3. Was 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!

    ReplyDelete
    Replies
    1. Creating Experts

      php 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/

      Delete
  4. Excelente el blog tanto la info como el diseño y la estetica del mismo, lo estoy poniendo entre mis favoritos, saludos cordiales.-

    ReplyDelete
  5. Hi there. PHP mysql is the growing trend now. It is a quite nice post PHP professionals. Thanks for sharing it.

    ReplyDelete
  6. Awesome 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.
    Thanks for sharing appropriate info.

    ReplyDelete
  7. wow now i understood it very well. thank you

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. I 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

    ReplyDelete
  10. HI, for some reason i get the following error. Can you help please|
    ( ! ) 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

    ReplyDelete
    Replies
    1. Did you follow all the steps correctly?

      Delete
  11. that was great tnx very much :)))))))))

    ReplyDelete
  12. Thanks a lot.Through this post I learned lot of new things to create my new blog.

    ReplyDelete
  13. I 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
    information.
    http://www.sqlservermasters.com/

    ReplyDelete
  14. Replies
    1. can you tell me where to find mysql 5.6 developer(1Z0-882) exam in PDF/VCE??

      Thanks:D

      Delete
  15. The 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.
    Thanks for sharing.

    Learnpact

    ReplyDelete
  16. pls provide...platforms for others to blog also

    ReplyDelete
  17. Nice post. I usually use PDO to avoid SQL injection.

    ReplyDelete
  18. Thank for sharing nice tutorial of creating blog using php and Mysql. It is very helpful to us.

    ReplyDelete
  19. Hi..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.

    ReplyDelete
  20. Nice blog post! But if you are newbie to mysql then you should learn Basics of MySQL and PHP communication in detail. Thank you.

    Kind Regards,
    Sahil Sharma
    www.webdevelopersahil.com

    ReplyDelete
  21. 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
    $query = mysql_query("SELECT title, FROM posts WHERE id=$post LIMIT 1");
    while($row = mysql_fetch_array($query)){
    echo $row['title'];
    }
    please help!

    ReplyDelete
  22. 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.
    thank you

    with regards,
    krishna

    ReplyDelete
  23. Good information for me. please keep updating us with new posts. thank you so much .

    ReplyDelete
  24. This blog is very informative for me please keep it up. Empowerment Technology

    ReplyDelete
  25. for more programming tutorial visit http://www.9code.in

    ReplyDelete
  26. Its one of my favorite PHP tutorial blogs and more insightful information.It fulfill my needs too.

    ReplyDelete
  27. thanks for sharing an awesome php tutorial for all beginners..

    ReplyDelete
  28. Its really helpful for me to understand where we i lost in my previous interview. Thanks.
    If anyone wants to Learn oracle in Chennai go to the Besant Technologies which is No.1 Training Institute in Chennai
    http://www.oracletraininginchennai.in

    ReplyDelete
  29. I got a job by saying this answer in my last interview. thanks for awesome help.
    I got more idea about Oracle from Besant Technologies. If anyone wants to get oracle Training in Chennai visit Besant Technologies.

    http://www.oracletraininginchennai.in

    ReplyDelete
  30. http://matrixnmedia-staging.com/common/fb_responsive/

    ReplyDelete
  31. Using PDO in PHP on Mysql coding makes itsecured.

    ReplyDelete
  32. Being a novice in coding how can I implement this one in one simple html website? Can anyone point me some realistic directions?

    ReplyDelete
  33. Great Post... Hope it would be helpful for Web Developer..
    webline infosoft - Dehradun is also helpful for designing and development the website.

    ReplyDelete
  34. such a nice and useful information, i request to please keep it up this blog

    ReplyDelete
  35. Good 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 :)

    ReplyDelete
  36. I 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.
    Online Booking system

    ReplyDelete
  37. I 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

    ReplyDelete
  38. Thanks for this great post! It has been very helpful for my site zachariahlarsen.com

    ReplyDelete
  39. I like your blog post and helpful for me make connection thanks for share How to connect MySQL Database in Php with easy Steps

    ReplyDelete
  40. Hello,
    if you guyz need to create some basic validation and logics to process a long html form,check out this.. www.kodebuilder.com

    ReplyDelete
  41. With years of experience in our hands and dedicated professionals in our panel, we come up as the most reliable and best service provider that could save your time, money and give you immense relief from hassles that usually comes with packing process.
    Packers and Movers Hyderabad or Movers and Packers Hyderabad
    Packers and Movers Bangalore or Movers and Packers Bangalore
    Packers and Movers Chennai or Movers and Packers Chennai
    Packers and Movers Pune or Movers and Packers Pune
    Packers and Movers Mumbai or Movers and Packers Mumbai
    Packers and Movers Delhi or Movers and Packers Delhi
    Packers and Movers Gurgaon or Movers and Packers Gurgaon

    ReplyDelete
  42. Replies
    1. I can't send my answer to the MySQLexam, Why??

      Delete
  43. 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.
    Starbucks Story of Growth Case Solution

    ReplyDelete
  44. Really this is very informative blog if anyone looking for learn php then we provided PHP Tutorial this is free online tutorial

    ReplyDelete
  45. Free Online Classified | Post Ad | US Classifieds - mukru.com usa no. 1 largest marketplace to buy, sell, find used product, servicees in your local area.
    http://www.mukru.com

    ReplyDelete
  46. This 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

    ReplyDelete
  47. You’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.

    ReplyDelete
  48. Hire PHP developers from a skilled and experienced PHP web development company which provides excellent PHP development services.

    ReplyDelete
  49. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about php

    ReplyDelete
  50. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about
    php

    ReplyDelete
  51. 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.
    resume writing services

    ReplyDelete
  52. 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

    ReplyDelete
  53. Wonderful 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!

    ReplyDelete
  54. Pls 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

    ReplyDelete
  55. Uhmmm... some info are: Don Formation House Ondo - Nigeria... the name for the blog sdbdream... thanks

    ReplyDelete

Follow by Email