News Articles (SQL/PHP Based)
Please Register to submit score.
| Average Score | 4.0 |
| Scores Submitted | 1 |
| Date Added | Mar 31, 2008 |
| Last Updated | Apr 01, 2008 |
| Tags | articles id news php script sql titles web webpage |
Introduction
This is a simple, (no graphics) webpage for displaying news from an SQL table with an add feature.
Ok, so the first thing you need to do, is create a new table within your database. either use phpMyAdmin, running this SQL code.
| Code: |
| CREATE TABLE `news` ( `id` INT( 255 ) NOT NULL AUTO_INCREMENT , `title` VARCHAR( 255 ) NOT NULL , `article` TEXT NOT NULL , `updated` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MYISAM ; |
or put it in a webpage, and view it (within a mysql_query). Running the SQL code through phpMyAdmin is the suggested way.
Secondly, create a new webpage, for example:
| Quote: |
| /home/www/www.website.com/news.php |
Then, paste the code from the snippet in.
The following code needs to be edited to your website.
| Code: |
| mysql_connect('host', 'login_to_sql', 'password_to_sql'); |
host = your mysql host. if you are using phpMyAdmin, you should get a message such as:
| Quote: |
| Welcome to phpMyAdmin MySQL 4.1.18-log running on fdb1.runhosting.com as your_username@xx.your.ip.xx |
The part you want from that is fdb1.runhosting.com
login_to_sql = your username, before the @ symbol in the previous quote.
password_to_sql = the password you used to get to your phpMyAdmin (or other SQL prog.)
Next, set the database_name as your databases name.
Now, you have your db set up and webpage running. You're pretty much ready to roll. Remember this web requires a log in (password is changed within the script:
| Code: |
| if ($_POST["pass"] == "jonesy") { |
Just change "jonesy" to "xx_yourpass".
[b]A working version of this script can be found at :
http://wfs.myartsonline.com/news
Password = jonesy
I'll leave it up for a week or two as an example.
If you have any questions, drop me a PM or leave a comment
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 8:05 pm
Posted on Mar 31, 2008 8:05 pm
I'd use a datetime or date and time fields for the date. You shouldn't store your date as a varchar. I also suggest adding a timestamp field to indicate the last updated date as well.
You also need a way to edit and delete posts.
You also need a way to edit and delete posts.
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 8:14 pm
Posted on Mar 31, 2008 8:14 pm
| Quote: |
| or displaying news from an SQL table with an add feature, i will add an edit/delete function by request. |
I'd agree on the timestamp, so i'll add it on later =P
Since the date doens't order the list, i havent bothered changing it from varchar :P`
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 9:14 pm
Posted on Mar 31, 2008 9:14 pm
Hey thats cool man.I got no idea hwo to even start in php or shoot bu tthis looks useful LOL unlike mIRC no offense but mirc has very little praticial application beyond irc servers/networks so this is neeat to see a piece of coe that most ppl use in forums an such.
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 9:22 pm
Posted on Mar 31, 2008 9:22 pm
I agree EL. mIRC is more of a hobby than anything while PHP is a potential career. You should get a shared web hosting account and start a site. We're working on some neat new functionality here to allow you to build your site into Hawkee with OpenSocial.
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 9:40 pm
Posted on Mar 31, 2008 9:40 pm
That sounds pretty cool Hawkee
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Mar 31, 2008 10:01 pm
Posted on Mar 31, 2008 10:01 pm
Umm i d love to but i dunno how to go about all that sadly sound awesome tho im on teh comp litterly 20+ hourse outta the day workin on my chat sie an codes wouldnt mind doin other things with my time sadly mIRC does get boring lol if you have some suggestion on gettin started liek ''PHP for Dumb asses'' it be cool if not thats cool theres always google =
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Apr 1, 2008 11:18 am
Posted on Apr 1, 2008 11:18 am
THanks for the comments EL, Hawkee, mountaindew.
Like i said, this is a very basic script. but shows a small amount of potential of PHP/SQL and how it can be used.
I think my methods in PHP/SQL are slightly elongated cos i dont know much of it xP
Like i said, this is a very basic script. but shows a small amount of potential of PHP/SQL and how it can be used.
I think my methods in PHP/SQL are slightly elongated cos i dont know much of it xP
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Apr 1, 2008 12:43 pm
Posted on Apr 1, 2008 12:43 pm
***BUMP***
UPDATED: Edit/Delete functions added
UPDATED: Edit/Delete functions added
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Apr 1, 2008 2:03 pm
Posted on Apr 1, 2008 2:03 pm
It's great that you added the edit/delete functions. I posted new news on the sample page :o
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Apr 1, 2008 3:49 pm
Posted on Apr 1, 2008 3:49 pm
This code is vulnerable to SQL Injection. You should always sanitize your $_GET and $_POST variables before using them in a query with mysql_real_escape_string(). Check this page for information on preventing an injection attack with PHP.
PHP Snippet:
News Articles (SQL/PHP Based)
Posted on Apr 2, 2008 6:09 pm
Posted on Apr 2, 2008 6:09 pm
Thanks for the links Hawkee, i've read through them and updated my current website, haha i just realised how vulnerable it actually was.
Security on this script is not necessary as it's designed to be simple, when i get a chance, i'll add the extra sanitizing :)
Security on this script is not necessary as it's designed to be simple, when i get a chance, i'll add the extra sanitizing :)






