Nov 20, 2009
Pages: 1, 2, 3

Php News Script - how to make news script that uses MySQL writen in PHP

free web hosting

Read Latest Entries..: (Post #20) by iGuest on Oct 21 2009, 07:02 PM.
What does it mean if I get this error on news.Php? ___________________________________________ Warning: mysql_query() [function.Mysql-query]: Access denied for user 'levi'@'lotus.X10hosting.Com' (using password: NO) in /home/levi/public_html/news.Php on line 7 Warning: mysql_query() [function.Mysql-query]: A link to the server could not be established in /home/levi/public_html/news.Php on line 7 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hom...
read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Php News Script - how to make news script that uses MySQL writen in PHP

Corey
How to make a News script with PHP + MySQL



So..in this tutorial i will explain how to create PHP news script.

first we have to create the table in My SQL..

with the code below you will do this ( you have to enter it into SQL field ..in PHPmyADMIN)

CODE


CREATE TABLE news ( id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY content (content) )





>>>> script files

1 file will show the news ,1 file will contain variables and with the third one we can add news.

we'll call the first file "news.php"

CODE


<?php


$query = "SELECT *," .
"DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
"FROM news ORDER BY id DESC LIMIT $news_limit"; // 1.
$result = mysql_query($query);

while($r=mysql_fetch_array($result)) // 2.
{
echo "<br><table width='100%'><tr bgcolor='$title_cell_color'><td>
<img src='$bullet'><b>$title</b> posted on $date</td></tr>
<tr bgcolor='$news_cell_color'><td>$content</td></tr>
</table><br>";

}

?>



explaination:

1. inlcuding variables into the script

2. selecting the table in the db,formating date, limiting the number of news the script is going to show.

3. now the script is writing the data form db into tables.



now we have to make another file which can add new news into db.

we will call it "add.php"

CODE


<?php
include "var.php"; // 1.
if ($action==add) // 2.
{
$title=$_POST['title'];
$content=$_POST['content']; // 3.
mysql_query("insert into news (title,content) VALUES ('$title','$content')");
echo "<a href='index.php'>Home</a>"; // 4.
}
else // 4.
{
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><form name=\"form1\" method=\"post\" action=\"add.php?action=add\">
<div align=\"center\">
<p>Title:
<input type=\"text\" name=\"textfield\">
</p>
<p>News content :
<textarea name=\"title\" cols=\"50\" rows=\"10\" id=\"title\"></textarea>
</p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Add\">
</p>
</div>
</form></td>
</tr>
</table>\n";
}


?>



explaination:

1. includeing variables into the script

2. if the $action id add..then the script is going to add data into the db,and if $action isn't selected,then the scipt is gonna show form for adding news.

3. the script is putting the data that we have entered into variables

4. if $action isn't set to "add" the script is showing a form for adding news



this is the third file....we are gonna define all important variables here..and we're gonna make a connection to db.

CODE


<?php
////////////////////////////////////////////////////////////////////////////////////////
$news_limit="xxxx"; // number of news that script shows
$user="xxxx"; // db username
$pass="xxxx"; // password
$db_name="xxxx"; // database name
$bullet="xxxx"; // path to the bullet image
$title_cell_color="xxxx"; // bg color for title cell in RGB...(black = #000000)
$news_cell_color="xxx"; // bg color for news cell in RGB...(black = #000000)
////////////////////////////////////////////////////////////////////////////////////////
$db = mysql_connect("localhost", "$user", "$pass");
mysql_select_db("$db_name", $db); //
?>



You have to change all the variables.



You can download all script files here.

http://tema.trap17.com/php/SNS-php.rar



..if you have some questions are if you have found a mistake in this script...please let me know. (post here)

 

 

 


Comment/Reply (w/o sign-up)

hype
Can you put the download file in zip instead of rar? I dont wanna download winrar for that....

Comment/Reply (w/o sign-up)

dtygel
Great script Corey!
Two questions:

1) Can I use some change of this script for a newsletter? I mean, is there a way to send the news genterated and stored in the database?

2) Is there a way to generate some reports (search reports) crossing more than one field, like "some words in the subject", and "sent before X day"?

Thanks a lot, I'm a newbie in php!

daniel (from Brasil)

Comment/Reply (w/o sign-up)

Corey
QUOTE(hype @ May 18 2005, 02:22 AM)
Can you put the download file in zip instead of rar? I dont wanna download winrar for that....
*



no problem...
here..
http://tema.trap17.com/php/SNS-php.zip


QUOTE(dtygel @ May 18 2005, 03:12 AM)
Great script Corey!
  Two questions:

        1) Can I use some change of this script for a newsletter? I mean, is there a way to send the news genterated and stored in the database?

        2) Is there a way to generate some reports (search reports) crossing more than one field, like "some words in the subject", and "sent before X day"?

      Thanks a lot, I'm a newbie in php!

          daniel (from Brasil)
*



1) yes...but afkors..you have to make some changes ...u have to make a script that pulls the data from db and sends it to users via e-mail

2) ....maybe...don't know it yet..

 

 

 


Comment/Reply (w/o sign-up)

karlo
http://www.karlo.ph.tc

On my website, I have a NEWS SCRIPT that I made, with pages support, bbcodes, and RSS feed support. smile.gif

Comment/Reply (w/o sign-up)

Van2003ko
Wow very useful infomation will used this in the future..

Comment/Reply (w/o sign-up)

rvalkass
On the subject of dtygel's suggestions:

1. Could this be done using the PHP mail() function?

2. A search could be done by asking the user for a search term in a text field and asking what to search in e.g Date, Title etc and also placing that in a variable. Then selecting the appropriate results from the SQL database.

The search could also help with the email, to ensure that only the current months news is mailed.

Just a thought smile.gif

Comment/Reply (w/o sign-up)

dtygel
Hi all,

rvalkass and corey showed a way, but I'm a terrible programmer (sorry...), so I would prefer to find some solution. My problem is the following: I'd like to send "automagically" the latest news in my website (which is still under construction smile.gif ); and also, I would like to let the user make some searchs on the news sent in the past. I took a look at karlo's site, but didn't find the news script he mentioned.

Now, about using the mail() function: wouldn't I be limited to the hourly limit in the server of e-mails sent? Or is the mail() function out of this account? Would it be better to use, say, the phplist software?

Thanks folks: I'm understanding a little bit more about php since I came accross this topic wink.gif

Daniel

Comment/Reply (w/o sign-up)

rvalkass
As the mail() function sends emails from an address you specify I belive you would be limited to the servers limits. I belive that PHPList also uses the mail function so would have the same problems. I think a mySQL query soemthing like the one below would allow for a search funtion:

CODE

mysql_query("SELECT title, content FROM news WHERE title='$search' ");


This would get all news entries where the title is equal to the search term. The variable $search would be a text box containing the search term. I may have got this code wrong, so please correct me. I am also unsure of whether the term has to exactly match that in the database, or just contain it. Everyone, please feel free to correct me or change this code. Thanks.

Comment/Reply (w/o sign-up)

dtygel
Great, Valkass!
Thank you for the answers.

Well, how do I get rid of the servers limits? Can mailman do that? Or should I contract a mailing service? (some suggestion?)

About the script: that was a suggestion of a simple search. I would like to give the user the possibility to cross between fields (maybe the AND syntax...): a cross-fields search.

Daniel

Comment/Reply (w/o sign-up)

Latest Entries

iGuest

What does it mean if I get this error on news.Php?

___________________________________________


Warning: mysql_query() [function.Mysql-query]: Access denied for user 'levi'@'lotus.X10hosting.Com' (using password: NO) in /home/levi/public_html/news.Php on line 7

Warning: mysql_query() [function.Mysql-query]: A link to the server could not be established in /home/levi/public_html/news.Php on line 7

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/levi/public_html/news.Php on line 9

____________________________________________

Where it says levi. That is my username on the server.


Comment/Reply (w/o sign-up)

iGuest
The zip and rar files are no longer available to download. Any chance of putting them back up?

Comment/Reply (w/o sign-up)

Spectre
Because you aren't specifying a password: '(using password: NO)'. Did you notice how old this thread was?

Comment/Reply (w/o sign-up)

skter4938
I got this error when all was done and done:

CODE
Warning: mysql_query(): Access denied for user 'webtodes'@'localhost' (using password: NO) in /home/webtodes/public_html/news/index.php on line 50

Warning: mysql_query(): A link to the server could not be established in /home/webtodes/public_html/news/index.php on line 50

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webtodes/public_html/news/index.php on line 52


and the username was webtodes_admin in the var.php file dry.gif

Why does it give me this error, even though I put in a different username?

Comment/Reply (w/o sign-up)

rvalkass
The <= thing means less than or equal to. There are loads of them used in all programming languages. Some of the most common ones are listed below:

< less than
> greater than
<= less than or equal to
>= greater than or equal to
== exactly equal to
!= not equal to

They can be very useful in all sorts of eventualities. I can't remember what they are collectively called (hopefully someone will help out smile.gif )

They can be used with dates, numbers, variables, times, all sorts of things.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2, 3
Similar Topics

Keywords : php, news, script, make, news, script, mysql, writen, php

  1. How To Make Php Newsletter Script
    (3)
  2. Php Guest Online Script
    (3)
    make an index.php copy and paste this code CODE $db_host = "localhost"; $db_user = "root";
    $db_pass = ""; $db_name = "test"; $dbc = mysql_connect($db_host, $db_user, $db_pass); $dbs =
    mysql_select_db($db_name); $tm = time(); $timeout = $tm - (30*60); if($_SERVER ){$ip=$_SERVER ;}
    else{$ip=$_SERVER ;} $brws = explode("(",$_SERVER ); $browser = $brws ; mysql_query("DELETE FROM
    guest WHERE actvtime mysql_query("INSERT INTO guest SET  time='".$tm."',
    ip='".$ip."', browser='".$browser."'"); $count =
    mysql_fetch_array(mysql_query("SELECT COUNT(*)....
  3. How To Make A View New Post Script?
    (5)
    Ok so i'm still working on the forum software i posted about a while back, but I have no idea
    how to do this. I want to make a view new post script, as this is one of the main things that my
    forum software dose not have that all other forums have. so does any body have an idea on how i
    would do this? Thanks.....
  4. Guessing Php Script
    (2)
    I am looking for: freeware php quess the person in the photo game script....
  5. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ....
  6. Mysql Error
    (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: You have an error
    in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
    syntax to use near ';INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`,
    `title`) ' at line 1 the code that is being excuted by the php file is this: C....
  7. Sending E-mails After News Update?
    Coding needed?!? (8)
    I need the following code or the idea how to reach this concept. Let's say, I have a database
    entry which is called "news", where all of the news stories are stored. If this database entry got
    modified, like the new post was added to the web-site by an administrator, the registered users will
    get some kind of email notification automatically, I mean the mails are sent automatically without
    the interaction of someone else. ....
  8. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way.......
  9. Best Php And Mysql Editor For Noobs
    anyone any php or mysql editor that is good for noob (11)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ....
  10. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  11. Need Help Installing Dolphin Community Script!
    (5)
    I'm not sure if this is the right place to post this but I really need help in installing the
    dolphin community script. I have absolutely no previous experience of scripts or programming. I
    would really appreciate if someone could walk me through it step-by-step, or even do it for me by
    logging into my cpanel. I have tried to install it my self but I'm a little confused. I'm
    sure it won't take very long at all for someone who has done this before.....
  12. Tools Needed!
    PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time.....
  13. Php Downloads Script
    (4)
    I've been looking all over the net for a PHP script which can provide an interface to browse a
    downloads database. The database could be powered by MySQL. If you know a script like this, please
    post it here. Thanks in advance, Ironchicken.....
  14. Mysql Won't Update
    (5)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's....
  15. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  16. Very Simple Online Now Script
    This is a very simple online now script. (4)
    Hi all, Its Aldo. anyways, I wont be using the method of pagination, i will just tell you how to
    make a basic online now script. When someone logs in, now take into consideration that the name of
    the username input is username ( First ,create a table in your database saying online now and add 2
    fields to it. id and username CODE id type=integer(INT) , auto increment, length =255 and
    username = VARCHAR length=the limit a username should be in your site now from there we take off
    : CODE //logged.php //authentication script //connection script //if connectio....
  17. Free Auction Script
    Any Suggestions? (7)
    Any free auction script suggested? I want it to be as many practical functions as possible, yet
    easy to manage. And more importantly, it is free! Appreciate your kind suggestions!....
  18. Phpmyadmin And Php And Mysql
    tutorial (1)
    hi i think phpmyadmin is nice script (3rdparti) to learn php and mysql , you can add database and
    then make tabel with rows and columns then you can customise (search , show rows , show columns ,
    add rows , delete rows) tabel in phpmyadmin when you are customise phpmyadmin , this script show you
    php code . you can use this code for browse in database . for example : showing tabel : CODE
    SELECT * FROM `tabelname` LIMIT 0 , 30 searching : CODE SELECT `columns` FROM `tabel` LIMIT
    0 , 30 you can use with while loop showing Ascending: CODE SELECT * FROM....
  19. Watermark Your Image With Simple Php Script
    found it on the net (39)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE // this script creates a watermarked image
    from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent
    gif image with the watermark - goes in the same directory as this script // where this....
  20. Creating Profiles In Php/mysql ?
    (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  21. Subquery In Mysql
    (8)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and
    SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database
    from MSAccess to MySQL. Help! Thanks.....
  22. Can You Add Images Into A Mysql Database?
    Using Php? (23)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  23. Transfer Variables To Another Php Script
    (11)
    Hello, I've one registration page where the users fills in their information, is it possible to
    trasnfer the things the fill in on the registration page to another script that does someting and
    returnes something to the first page like true/false and then the registration gives an error
    messange if the other php script returned false? Something like the script "activates" another
    script that does something and returnes the result back to the original script. Best Regards ....
  24. Parse: Error Unexpected T_lnumber
    php parse error when running script (4)
    Hi. I've just created a php script. The main object of the script is to delete some old files
    and replace it with a new file with some new content, effectively moving the contents from one file
    to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
    Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) { $a_B++; }
    $new_page_contents = " " . $_POST . " " . $_POST . " include
    \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen($a_B . ".cmat", "w+");
    fwri....
  25. Increment A Mysql Column
    how to increment a MySQL column one unit (8)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  26. Script: Php Jukebox
    A one file script! (6)
    This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
    called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
    and put it in a folder called 'music': CODE PHP jukebox ©2005 Craig lloyd.
    All rights reserved. Visit cragllo.com for more scripts --> /** * ©2005 Craig lloyd. All rights
    reserved. * * Mod Title:           Simple PHP Jukebox * Author:              Craig Lloyd * Author
    Email:        cragllo@cragllo.com * Author Homepage:     http://www.cragllo.com/ * Des....
  27. Many Php Script Sites
    (18)
    Hi I find many sites has PHP scripts :: QUOTE http://www.proxy2.de/scripts.php
    http://www.free-php.net http://knubbe.t35.com/ http://www.ngcoders.com/
    http://www.oxyscripts.com/ http://www.phparena.net/ http://www.1phpstreet.com/
    http://px.sklar.com/ http://www.scoznet.com/ http://php.resourceindex.com/ /blink.gif"
    style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" />....
  28. Problem On Mysql "order By"
    (6)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx....
  29. Mysql Password
    (4)
    Hey guys quick question about trap 17s mysql version. How do i change the password to the database?
    I cant seem to find online help for this version anywhere. Any help is very apperciated!....
  30. Mysql Question:
    (7)
    what do I need to input to create a new user and pass. I've tried before, but it kept giving me
    an error like I wasn't allows to creat users. Please note that this is on my computer. So, I was
    also wondering how to 'log in' to root user so that i can make a new user. Thanks in
    advance.....

    1. Looking for php, news, script, make, news, script, mysql, writen, php

Searching Video's for php, news, script, make, news, script, mysql, writen, php
See Also,
advertisement


Php News Script - how to make news script that uses MySQL writen in PHP

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com